import os
import sys
import time
import shutil
import pymysql
import requests
import warnings
import datetime
import pandas as pd
from selenium import webdriver
from sqlalchemy import create_engine
from dbutils.pooled_db import PooledDB
from ssh_operate import get_web_password
from ssh_cvt_recovery import initial_data
from selenium.webdriver.common.by import By
from urllib.parse import quote_plus as urlquote
from selenium.webdriver.chrome.service import Service
from global_parameter import fs_voltage_transformer_configs, DB_NAME, chromedriver_path, txt_path, ip, os_password, \
    username
from Algorithm_voltage_test import create_collect_voltage, execute_sql, create_collect_voltage_no_truncate
from Algorithm_current_test import create_collect_current, execute_sql, create_collect_current_no_truncate

# 忽略警告信息
warnings.filterwarnings('ignore')


class Logger(object):
    def __init__(self, fileN='Default.log'):
        self.terminal = sys.stdout
        self.log = open(fileN, 'w')

    def write(self, message):
        '''print实际相当于sys.stdout.write'''
        self.terminal.write(message)
        self.log.write(message)

    def flush(self):
        pass


sys.stdout = Logger('./logs/log.txt')  # 调用print时相当于Logger().write()

# 清空csv_results
if os.path.exists("./csv_results"):
    # 如果文件夹存在，则使用 shutil.rmtree() 删除文件夹及其内容
    shutil.rmtree("./csv_results")
if os.path.exists("./txt_result"):
    # 如果文件夹存在，则使用 shutil.rmtree() 删除文件夹及其内容
    shutil.rmtree("./txt_result")
os.mkdir("./csv_results")
os.mkdir("./txt_result")
print("清空csv_results文件夹")
print("清空txt_result文件夹")


def add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm=[]):
    """
    添加电压线路
    :param DB_HOST:
    :param DB_NAME:
    :param configs:
    :return:
    """
    POOL = PooledDB(creator=pymysql, maxconnections=6, mincached=2, maxcached=5, maxshared=3, blocking=True,
                    maxusage=None, setsession=[], ping=0, host=DB_HOST, port=3306, user='oetsky', password='Oetsky@123',
                    database=DB_NAME, charset='utf8')
    conn = POOL.connection()
    cursor = conn.cursor()

    cursor.execute("TRUNCATE fs_voltage_transformer;")
    print("已清空电压互感器信息表")

    for config in fs_voltage_transformer_configs:
        cursor.execute("INSERT INTO `fs_voltage_transformer` VALUES ({});".format(config))
        conn.commit()

    # transformer_coefficient = [150, 150, 150, 150, 150, 150]
    line = int(len(transformer_parm) / 3)
    for channel in range(line):
        cursor.execute(
            "UPDATE fs_voltage_transformer set rated_load={} where line_channel={} and phase_seq='A';".format(
                transformer_parm[channel * 3], channel + 1))
        cursor.execute(
            "UPDATE fs_voltage_transformer set rated_load={} where line_channel={} and phase_seq='B';".format(
                transformer_parm[channel * 3 + 1], channel + 1))
        cursor.execute(
            "UPDATE fs_voltage_transformer set rated_load={} where line_channel={} and phase_seq='C';".format(
                transformer_parm[channel * 3 + 2], channel + 1))
        conn.commit()
    cursor.close()
    conn.close()


def set_tcp_interface_status(DB_HOST, DB_NAME, config):
    """
    添加电压线路
    :param DB_HOST:
    :param DB_NAME:
    :param configs:
    :return:
    """
    POOL = PooledDB(creator=pymysql, maxconnections=6, mincached=2, maxcached=5, maxshared=3, blocking=True,
                    maxusage=None, setsession=[], ping=0, host=DB_HOST, port=3306, user='oetsky', password='Oetsky@123',
                    database=DB_NAME, charset='utf8')
    conn = POOL.connection()
    cursor = conn.cursor()

    cursor.execute("TRUNCATE dv_tcp_setting;")
    print("已清空TCP/IP通信配置表")
    cursor.execute(
        "INSERT INTO `dv_tcp_setting` (`id`, `device_name`, `device_type`, `agreement_type`, `ip_addr`, `ip_port`, `interface_status`, `create_time`, `update_time`, `remark`, `device_code`) VALUES ({});".format(
            config))
    conn.commit()
    cursor.close()
    conn.close()


def get_cookie(browser, ip, port, username, password):
    """
    使用selenium登录网页，获取cookie，供后续接口调用
    :param browser:
    :param ip:
    :param port:
    :param username:
    :param password:
    :return:
    """
    browser.get("http://{}:{}/login".format(ip, port))
    time.sleep(1)
    browser.find_element(By.NAME, 'username').send_keys(username)  # 填入用户名
    time.sleep(1)
    browser.find_element(By.NAME, 'password').send_keys(password)  # 填入密码
    time.sleep(1)
    browser.find_element(By.ID, "btnSubmit").click()  # 填入密码
    cookies_list = browser.get_cookies()
    cookie_value = cookies_list[0].get("value")
    print(cookie_value)
    time.sleep(1)
    return cookie_value


def remove_channel(ip, port, username, ids):
    """
    触发时间驱动计算电压数据
    :param ip:
    :param port:
    :param cookie_value:
    :return:
    """
    password_web = get_web_password(ip, port=10088, username="oetsky", password=os_password)
    service = Service(chromedriver_path)
    option = webdriver.ChromeOptions()
    # 不弹出chrome浏览器
    option.add_argument("headless")
    browser = webdriver.Chrome(service=service, options=option)
    cookie_value = get_cookie(browser, ip, port, username, password_web)
    browser.close()
    headers = {
        "Accept": "*/*",
        "Accept-Encoding": "gzip, deflate",
        "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
        "Connection": "keep-alive",
        "Content-Length": "0",
        "Cookie": "JSESSIONID={}".format(cookie_value),
        "Host": "{}:{}".format(ip, port),
        "Origin": "http://{}:{}".format(ip, port),
        "Referer": "http://{}:{}/monitor/job".format(ip, port),
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.44",
        "X-Requested-With": "XMLHttpRequest"
    }
    body = {'ids': ids}  # 参数为dict形式
    print(body)
    requests.post("http://{}:{}/currentchannel/currentchannel/remove".format(ip, port), headers=headers, timeout=5,
                  data=body)


def add_current_4_channel(ip, port, username):
    """
    触发时间驱动计算电压数据
    :param ip:
    :param port:
    :param cookie_value:
    :return:
    """
    password_web = get_web_password(ip, port=10088, username="oetsky", password=os_password)
    service = Service(chromedriver_path)
    option = webdriver.ChromeOptions()
    # 不弹出chrome浏览器
    option.add_argument("headless")
    browser = webdriver.Chrome(service=service, options=option)
    cookie_value = get_cookie(browser, ip, port, username, password_web)
    browser.close()
    headers = {
        "Accept": "*/*",
        "Accept-Encoding": "gzip, deflate",
        "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
        "Connection": "keep-alive",
        "Content-Length": "0",
        "Cookie": "JSESSIONID={}".format(cookie_value),
        "Host": "{}:{}".format(ip, port),
        "Origin": "http://{}:{}".format(ip, port),
        "Referer": "http://{}:{}/monitor/job".format(ip, port),
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.44",
        "X-Requested-With": "XMLHttpRequest"
    }
    channel_1 = {"boardNum": 6,
                 "unitId": 1,
                 "stationType": 2,
                 "boardNumType": "1_6_2",
                 "unitTypeChannelCode": "1_02_6_1",
                 "channelNum": 1,
                 "channelName": 1,
                 "channelLevel": 5,
                 "appSvId": None,
                 "groupChannel": None,
                 "unitMd5": None,
                 "unitName": None}  # 参数为dict形式
    channel_2 = {"boardNum": 6,
                 "unitId": 1,
                 "stationType": 2,
                 "boardNumType": "1_6_2",
                 "unitTypeChannelCode": "1_02_6_2",
                 "channelNum": 2,
                 "channelName": 2,
                 "channelLevel": 5,
                 "appSvId": None,
                 "groupChannel": None,
                 "unitMd5": None,
                 "unitName": None}  # 参数为dict形式
    channel_100 = {"boardNum": 6,
                   "unitId": 1,
                   "stationType": 2,
                   "boardNumType": "1_6_2",
                   "unitTypeChannelCode": "1_02_6_3",
                   "channelNum": 100,
                   "channelName": 100,
                   "channelLevel": 5,
                   "appSvId": None,
                   "groupChannel": None,
                   "unitMd5": None,
                   "unitName": None}  # 参数为dict形式
    channel_101 = {"boardNum": 6,
                   "unitId": 1,
                   "stationType": 2,
                   "boardNumType": "1_6_2",
                   "unitTypeChannelCode": "1_02_6_4",
                   "channelNum": 101,
                   "channelName": 101,
                   "channelLevel": 5,
                   "appSvId": None,
                   "groupChannel": None,
                   "unitMd5": None,
                   "unitName": None}  # 参数为dict形式
    print(channel_1)
    print(channel_2)
    print(channel_100)
    print(channel_101)

    # 使用接口方式添加电流线路
    POOL = PooledDB(creator=pymysql, maxconnections=6, mincached=2, maxcached=5, maxshared=3, blocking=True,
                    maxusage=None, setsession=[], ping=0, host=ip, port=3306, user='oetsky', password='Oetsky@123',
                    database=DB_NAME, charset='utf8')
    conn = POOL.connection()
    cursor = conn.cursor()

    cursor.execute("TRUNCATE dv_current_channel;")
    cursor.execute("TRUNCATE addr_current_channel;")

    requests.post("http://{}:{}/currentchannel/currentchannel/add".format(ip, port), headers=headers, timeout=5,
                  data=channel_1)
    requests.post("http://{}:{}/currentchannel/currentchannel/add".format(ip, port), headers=headers, timeout=5,
                  data=channel_2)
    requests.post("http://{}:{}/currentchannel/currentchannel/add".format(ip, port), headers=headers, timeout=5,
                  data=channel_100)
    requests.post("http://{}:{}/currentchannel/currentchannel/add".format(ip, port), headers=headers, timeout=5,
                  data=channel_101)


def add_current_2_channel(ip, port, username):
    """
    触发时间驱动计算电压数据
    :param ip:
    :param port:
    :param cookie_value:
    :return:
    """
    password_web = get_web_password(ip, port=10088, username="oetsky", password=os_password)
    service = Service(chromedriver_path)
    option = webdriver.ChromeOptions()
    # 不弹出chrome浏览器
    option.add_argument("headless")
    browser = webdriver.Chrome(service=service, options=option)
    cookie_value = get_cookie(browser, ip, port, username, password_web)
    browser.close()
    headers = {
        "Accept": "*/*",
        "Accept-Encoding": "gzip, deflate",
        "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
        "Connection": "keep-alive",
        "Content-Length": "0",
        "Cookie": "JSESSIONID={}".format(cookie_value),
        "Host": "{}:{}".format(ip, port),
        "Origin": "http://{}:{}".format(ip, port),
        "Referer": "http://{}:{}/monitor/job".format(ip, port),
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.44",
        "X-Requested-With": "XMLHttpRequest"
    }
    channel_1 = {"boardNum": 6,
                 "unitId": 1,
                 "stationType": 2,
                 "boardNumType": "1_6_2",
                 "unitTypeChannelCode": "1_02_6_1",
                 "channelNum": 1,
                 "channelName": 1,
                 "channelLevel": 5,
                 "appSvId": None,
                 "groupChannel": None,
                 "unitMd5": None,
                 "unitName": None}  # 参数为dict形式
    channel_100 = {"boardNum": 6,
                   "unitId": 1,
                   "stationType": 2,
                   "boardNumType": "1_6_2",
                   "unitTypeChannelCode": "1_02_6_2",
                   "channelNum": 100,
                   "channelName": 100,
                   "channelLevel": 5,
                   "appSvId": None,
                   "groupChannel": None,
                   "unitMd5": None,
                   "unitName": None}  # 参数为dict形式
    print(channel_1)
    print(channel_100)

    # 使用接口方式添加电流线路
    POOL = PooledDB(creator=pymysql, maxconnections=6, mincached=2, maxcached=5, maxshared=3, blocking=True,
                    maxusage=None, setsession=[], ping=0, host=ip, port=3306, user='oetsky', password='Oetsky@123',
                    database=DB_NAME, charset='utf8')
    conn = POOL.connection()
    cursor = conn.cursor()

    cursor.execute("TRUNCATE dv_current_channel;")
    cursor.execute("TRUNCATE addr_current_channel;")

    requests.post("http://{}:{}/currentchannel/currentchannel/add".format(ip, port), headers=headers, timeout=5,
                  data=channel_1)
    requests.post("http://{}:{}/currentchannel/currentchannel/add".format(ip, port), headers=headers, timeout=5,
                  data=channel_100)


def stop_calc(ip, port, username, password):
    """
    触发时间驱动计算电压数据
    :param ip:
    :param port:
    :param cookie_value:
    :return:
    """
    service = Service(chromedriver_path)
    option = webdriver.ChromeOptions()
    # 不弹出chrome浏览器
    option.add_argument("headless")
    browser = webdriver.Chrome(service=service, options=option)
    cookie_value = get_cookie(browser, ip, port, username, password)
    browser.close()

    headers = {
        "Accept": "*/*",
        "Accept-Encoding": "gzip, deflate",
        "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
        "Connection": "keep-alive",
        "Content-Length": "0",
        "Cookie": "JSESSIONID={}".format(cookie_value),
        "Host": "{}:{}".format(ip, port),
        "Origin": "http://{}:{}".format(ip, port),
        "Referer": "http://{}:{}/monitor/job".format(ip, port),
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.44",
        "X-Requested-With": "XMLHttpRequest"
    }
    try:
        requests.post("http://{}:{}/timeDrivenTask/stopCalculate".format(ip, port), headers=headers, timeout=5)
    except:
        pass


def get_calc_status(ip, port, cookie_value):
    """
    触发时间驱动计算电压数据
    :param ip:
    :param port:
    :param cookie_value:
    :return:
    """
    headers = {
        "Accept": "*/*",
        "Accept-Encoding": "gzip, deflate",
        "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
        "Connection": "keep-alive",
        "Content-Length": "0",
        "Cookie": "JSESSIONID={}".format(cookie_value),
        "Host": "{}:{}".format(ip, port),
        "Origin": "http://{}:{}".format(ip, port),
        "Referer": "http://{}:{}/monitor/job".format(ip, port),
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.44",
        "X-Requested-With": "XMLHttpRequest"
    }
    try:
        res = requests.post("http://{}:{}/timeDrivenTask/getCalculateStatus".format(ip, port), headers=headers,
                            timeout=5)
    except:
        pass
    res_str = str(res.content, encoding="utf-8")
    # print(res_str)
    return res_str


def add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data):
    """
    添加电压线路
    :param DB_HOST:
    :param DB_NAME:
    :param channel_config:
    :return:
    """
    POOL = PooledDB(creator=pymysql, maxconnections=6, mincached=2, maxcached=5, maxshared=3, blocking=True,
                    maxusage=None, setsession=[], ping=0, host=DB_HOST, port=3306, user='oetsky', password='Oetsky@123',
                    database=DB_NAME, charset='utf8')
    conn = POOL.connection()
    cursor = conn.cursor()

    cursor.execute("TRUNCATE dv_voltage_channel;")
    cursor.execute("TRUNCATE dv_voltage_line_group_channel;")
    cursor.execute("TRUNCATE algo_config;")
    cursor.execute("TRUNCATE addr_current_channel;")
    cursor.execute("TRUNCATE dv_current_channel;")
    print("已清空电压线路配置表")
    print("已清空电压线路组通道关联表")
    print("已清空算法配置表")

    cursor.execute("TRUNCATE da_voltage_data_temp;")
    print("已清空半年数据表")
    cursor.execute("TRUNCATE err_voltage_error;")
    print("已清空误差计算数据表")
    cursor.execute("TRUNCATE err_voltage_status;")
    print("已清空数据预处理状态标记表")
    cursor.execute("TRUNCATE err_voltage_avg;")
    print("已清空误差计算均值表")
    cursor.execute("TRUNCATE err_voltage_slide_window;")
    print("已清空误差计算滑窗表")
    cursor.execute("TRUNCATE inspection_event_info;")
    print("已清空装置自诊断事件表")

    cursor.execute("TRUNCATE err_voltage_error_pile;")
    cursor.execute("TRUNCATE err_voltage_matrix_status;")
    cursor.execute("TRUNCATE err_voltage_pre_pile_record;")
    cursor.execute("TRUNCATE err_voltage_dynamic_slide_window;")

    for config in channel_config:
        cursor.execute("INSERT INTO `dv_voltage_channel` VALUES ({});".format(config))
        conn.commit()
    for config_group in channel_config_group:
        cursor.execute("INSERT INTO `dv_voltage_line_group_channel` VALUES ({});".format(config_group))
        conn.commit()
    for algo_config in algo_config_data:
        cursor.execute("INSERT INTO `algo_config` VALUES ({});".format(algo_config))
        conn.commit()
    cursor.close()
    conn.close()


def add_current_channel(DB_HOST, DB_NAME, channel_config, addr_config, channel_config_group, algo_config_data,
                        current_sql_config, interface=False):
    """
    添加电压线路
    :param DB_HOST:
    :param DB_NAME:
    :param channel_config:
    :return:
    """
    for sql in current_sql_config:
        execute_sql(sql)
    set_sql_current_amp(DB_HOST, DB_NAME, min_frequency=49, max_frequency=51)
    print("设置最小频率49HZ,最大频率51HZ--current")
    POOL = PooledDB(creator=pymysql, maxconnections=6, mincached=2, maxcached=5, maxshared=3, blocking=True,
                    maxusage=None, setsession=[], ping=0, host=DB_HOST, port=3306, user='oetsky', password='Oetsky@123',
                    database=DB_NAME, charset='utf8')
    conn = POOL.connection()
    cursor = conn.cursor()

    cursor.execute("TRUNCATE dv_current_channel;")
    cursor.execute("TRUNCATE dv_voltage_channel;")
    cursor.execute("TRUNCATE dv_voltage_line_group_channel;")
    cursor.execute("TRUNCATE algo_config;")
    cursor.execute("TRUNCATE addr_current_channel;")
    print("已清空电流线路配置")
    print("已清空电压线路配置")
    print("已清空电压线路组通道关联表")
    print("已电流表计地址-对应通道表")
    print("已清空算法配置表")

    cursor.execute("TRUNCATE da_voltage_data_temp;")
    print("已清空半年数据表")
    cursor.execute("TRUNCATE err_voltage_error;")
    print("已清空误差计算数据表")
    cursor.execute("TRUNCATE err_voltage_status;")
    print("已清空数据预处理状态标记表")
    cursor.execute("TRUNCATE err_voltage_avg;")
    print("已清空误差计算均值表")
    cursor.execute("TRUNCATE err_voltage_slide_window;")
    print("已清空误差计算滑窗表")
    cursor.execute("TRUNCATE inspection_event_info;")
    print("已清空装置自诊断事件表")

    cursor.execute("TRUNCATE err_voltage_error_pile;")
    print("已清空err_voltage_error_pile")
    cursor.execute("TRUNCATE err_voltage_matrix_status;")
    print("已清空err_voltage_matrix_status")
    cursor.execute("TRUNCATE err_voltage_pre_pile_record;")
    print("已清空err_voltage_pre_pile_record")
    cursor.execute("TRUNCATE err_voltage_dynamic_slide_window;")
    print("已清空err_voltage_dynamic_slide_window")

    for config in channel_config:
        print("0")
        cursor.execute("INSERT INTO `dv_current_channel` VALUES ({});".format(config))
        print("1")
        conn.commit()
    for addr in addr_config:
        cursor.execute(
            "INSERT INTO `addr_current_channel` (`id`, `channel_num`, `meter_addr`) VALUES ({});".format(addr))
        print("2")
        conn.commit()
    for config_group in channel_config_group:
        cursor.execute("INSERT INTO `dv_voltage_line_group_channel` VALUES ({});".format(config_group))
        print("3")
        conn.commit()
    for algo_config in algo_config_data:
        cursor.execute("INSERT INTO `algo_config` VALUES ({});".format(algo_config))
        print("4")
        conn.commit()
    cursor.close()
    conn.close()


def only_add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data):
    """
    添加电压线路
    :param DB_HOST:
    :param DB_NAME:
    :param channel_config:
    :return:
    """
    POOL = PooledDB(creator=pymysql, maxconnections=6, mincached=2, maxcached=5, maxshared=3, blocking=True,
                    maxusage=None, setsession=[], ping=0, host=DB_HOST, port=3306, user='oetsky', password='Oetsky@123',
                    database=DB_NAME, charset='utf8')
    conn = POOL.connection()
    cursor = conn.cursor()

    cursor.execute("TRUNCATE dv_voltage_channel;")
    cursor.execute("TRUNCATE dv_voltage_line_group_channel;")
    print("已清空电压线路配置表")
    print("已清空电压线路组通道关联表")

    for config in channel_config:
        cursor.execute("INSERT INTO `dv_voltage_channel` VALUES ({});".format(config))
        conn.commit()
    for config_group in channel_config_group:
        cursor.execute("INSERT INTO `dv_voltage_line_group_channel` VALUES ({});".format(config_group))
        conn.commit()
    cursor.close()
    conn.close()


def only_add_current_channel(DB_HOST, DB_NAME, channel_config, addr_config, channel_config_group, algo_config_data):
    """
    添加电压线路
    :param DB_HOST:
    :param DB_NAME:
    :param channel_config:
    :return:
    """
    POOL = PooledDB(creator=pymysql, maxconnections=6, mincached=2, maxcached=5, maxshared=3, blocking=True,
                    maxusage=None, setsession=[], ping=0, host=DB_HOST, port=3306, user='oetsky', password='Oetsky@123',
                    database=DB_NAME, charset='utf8')
    conn = POOL.connection()
    cursor = conn.cursor()

    cursor.execute("TRUNCATE dv_current_channel;")
    cursor.execute("TRUNCATE addr_current_channel;")
    print("已清空电流线路配置")
    print("已电流表计地址-对应通道表")

    for config in channel_config:
        cursor.execute("INSERT INTO `dv_current_channel` VALUES ({});".format(config))
        conn.commit()
    for addr in addr_config:
        cursor.execute(
            "INSERT INTO `addr_current_channel` (`id`, `channel_num`, `meter_addr`) VALUES ({});".format(addr))
        conn.commit()
    cursor.close()
    conn.close()


def truncate_mysql_tables(DB_HOST, DB_NAME):
    """
    添加电压线路
    :param DB_HOST:
    :param DB_NAME:
    :param channel_config:
    :return:
    """
    POOL = PooledDB(creator=pymysql, maxconnections=6, mincached=2, maxcached=5, maxshared=3, blocking=True,
                    maxusage=None, setsession=[], ping=0, host=DB_HOST, port=3306, user='oetsky', password='Oetsky@123',
                    database=DB_NAME, charset='utf8')
    conn = POOL.connection()
    cursor = conn.cursor()

    cursor.execute("TRUNCATE dv_voltage_channel;")
    cursor.execute("TRUNCATE dv_voltage_line_group_channel;")
    cursor.execute("TRUNCATE algo_config;")
    cursor.execute("TRUNCATE fs_voltage_transformer;")

    cursor.execute("TRUNCATE da_voltage_data_temp;")
    cursor.execute("TRUNCATE err_voltage_error;")
    cursor.execute("TRUNCATE err_voltage_status;")
    cursor.execute("TRUNCATE err_voltage_avg;")
    cursor.execute("TRUNCATE err_voltage_slide_window;")
    cursor.execute("TRUNCATE err_voltage_error_pile;")
    cursor.execute("TRUNCATE err_voltage_matrix_status;")
    cursor.execute("TRUNCATE err_voltage_pre_pile_record;")
    cursor.execute("TRUNCATE err_voltage_dynamic_slide_window;")
    print("停止计算，清空所有表")

    cursor.close()
    conn.close()


def wait_evevt_done():
    """
    等待分钟为0或者5的时间点
    :return:
    """
    now_time = datetime.datetime.now()
    minute_time = datetime.datetime.now().minute
    print(now_time)
    print(minute_time)
    certain_minute = [i * 5 + 0 for i in range(12)]
    # 列表排序
    certain_minute.sort()
    print(certain_minute)
    for i in range(60 * 5):
        if minute_time in certain_minute:
            break
        else:
            time.sleep(1)
            minute_time = datetime.datetime.now().minute
            now_time = datetime.datetime.now()
            print("wait_evevt_done")
            print(minute_time)
            print(now_time)
    # 等待30秒触发自诊断事件,为防止自诊断事件事件过久，建议设置60S
    # time.sleep(40)
    time.sleep(60)


def read_xlsx_append_sql(ip, DB_NAME):
    """
    读取xlsx文件，插入到sql中
    :param DB_HOST:
    :param DB_NAME:
    :return:
    """
    pd_data = pd.read_excel("./da_voltage_data_temp_比差为0.xlsx")
    pre_time = (datetime.date.today() + datetime.timedelta(days=-1)).strftime("%Y-%m-%d")
    for i in range(len(pd_data)):
        str_hms = pd_data["collect_time"][i].strftime(" %H:%M:%S")
        pd_data["collect_time"][i] = datetime.datetime.strptime(pre_time + str_hms, "%Y-%m-%d %H:%M:%S")
        pd_data["create_time"][i] = datetime.datetime.strptime(pre_time + str_hms, "%Y-%m-%d %H:%M:%S")

    userName = "oetsky"
    password = "Oetsky@123"
    dbHost = ip
    dbPort = 3306
    dbName = DB_NAME
    DB_CONNECT = f'mysql+pymysql://{userName}:{urlquote(password)}@{dbHost}:{dbPort}/{dbName}?charset=utf8'
    engine = create_engine(
        DB_CONNECT,
        max_overflow=50,  # 超过连接池大小外最多创建的连接
        pool_size=50,  # 连接池大小
        pool_timeout=5,  # 池中没有线程最多等待的时间，否则报错
        pool_recycle=-1,  # 多久之后对线程池中的线程进行一次连接的回收（重置）
        # encoding='utf-8',
        echo=False
    )
    pd_data.to_sql(name="da_voltage_data_temp", con=engine, if_exists="replace", index=False)


def export_csv(DB_HOST, DB_NAME, scene_name):
    """
    读取SQL，导出csv
    :param DB_HOST:
    :param DB_NAME:
    :return:
    """
    os.mkdir("./csv_results/{}".format(scene_name))
    con_user = pymysql.connect(host=DB_HOST, port=3306, user="oetsky", password='Oetsky@123', db=DB_NAME,
                               charset='utf8')
    df_dv_voltage_channel = pd.read_sql("SELECT * FROM dv_voltage_channel;", con_user)
    df_dv_current_channel = pd.read_sql("SELECT * FROM dv_current_channel;", con_user)
    df_da_current_data_temp = pd.read_sql("SELECT * FROM da_current_data_temp;", con_user)
    df_dv_tcp_setting = pd.read_sql("SELECT * FROM dv_tcp_setting;", con_user)
    df_dv_voltage_line_group_channel = pd.read_sql("SELECT * FROM dv_voltage_line_group_channel;", con_user)
    df_da_voltage_data_temp = pd.read_sql("SELECT * FROM da_voltage_data_temp;", con_user)
    df_inspection_event_info = pd.read_sql("SELECT * FROM inspection_event_info;", con_user)
    df_sys_config = pd.read_sql("SELECT * FROM sys_config;", con_user)
    # 去除已经恢复时间中，未恢复的记录
    df_recovered = pd.read_sql("SELECT * FROM inspection_event_info WHERE exception_id is NOT NULL;", con_user)
    df_not_recovered = pd.read_sql(
        "SELECT * FROM inspection_event_info WHERE exception_id is NULL and id NOT IN (SELECT DISTINCT exception_id FROM inspection_event_info WHERE exception_id IS NOT NULL);",
        con_user)
    con_user.close()

    str_now_time = datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
    df_dv_voltage_channel.to_csv(
        "./csv_results/{}/{}_df_dv_voltage_channel_{}.csv".format(scene_name, scene_name, str_now_time))
    df_dv_voltage_line_group_channel.to_csv(
        "./csv_results/{}/{}_df_dv_voltage_line_group_channel_{}.csv".format(scene_name, scene_name, str_now_time))
    df_da_voltage_data_temp.to_csv(
        "./csv_results/{}/{}_da_voltage_data_temp_{}.csv".format(scene_name, scene_name, str_now_time))
    df_inspection_event_info.to_csv(
        "./csv_results/{}/{}_df_inspection_event_info_{}.csv".format(scene_name, scene_name, str_now_time))
    df_dv_current_channel.to_csv(
        "./csv_results/{}/{}_df_dv_current_channel_{}.csv".format(scene_name, scene_name, str_now_time))
    df_da_current_data_temp.to_csv(
        "./csv_results/{}/{}_df_da_current_data_temp_{}.csv".format(scene_name, scene_name, str_now_time))
    df_dv_tcp_setting.to_csv(
        "./csv_results/{}/{}_df_dv_tcp_setting_{}.csv".format(scene_name, scene_name, str_now_time))
    df_sys_config.to_csv(
        "./csv_results/{}/{}_df_sys_config_{}.csv".format(scene_name, scene_name, str_now_time))
    return df_recovered, df_not_recovered


def write_txt(content):
    """
    写入结果到txt
    """
    with open(txt_path, "a") as f:
        f.write(content)


def check_test_result(scene_name, df, list_ratio, list_angle, list_status, list_msg):
    sql_ratio = df["aa_ratio_error"].to_list() + df["bb_ratio_error"].to_list() + df["cc_ratio_error"].to_list()
    sql_angle = df["aa_angle_error"].to_list() + df["bb_angle_error"].to_list() + df["cc_angle_error"].to_list()
    sql_status = df["calculate_status"].to_list()
    sql_msg = df["calculate_msg"].to_list()
    print(sql_ratio)
    print(sql_angle)
    print(sql_status)
    print(sql_msg)
    result = "pass"

    if len(list_ratio) == len(sql_ratio) and len(list_angle) == len(sql_angle) and \
            len(list_status) == len(sql_status) and len(list_msg) == len(sql_msg):
        for index, ratio in enumerate(list_ratio):
            if ratio and ratio != sql_ratio[index]:
                result = "fail"
        for index, angle in enumerate(list_angle):
            if angle and angle != sql_angle[index]:
                result = "fail"
        for index, status in enumerate(list_status):
            if status and status != sql_status[index]:
                result = "fail"
        for index, msg in enumerate(list_msg):
            if msg and msg != sql_msg[index]:
                result = "fail"
    else:
        print("列表数据和SQL数据条数不对应")
        print(list_ratio, list_angle, list_status, list_msg)
        print(sql_ratio, sql_angle, sql_status, sql_msg)
        result = "fail"
    write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1400(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    # try:
    print("{}：开始测试".format(scene_name))
    DB_HOST = ip

    # 第一步，等待1、2、3或者6,7,8的时间开始测试
    wait_time()
    print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

    # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
    set_tcp_interface_status(DB_HOST, DB_NAME,
                             "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
    add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
    add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
    print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

    # 第三步，生成并导入数据库数据
    create_collect_voltage(
        p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
            "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
    assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
    recovered_time = (datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=1)).strftime(
        "%Y-%m-%d %H:%M:%S")
    execute_sql("DELETE FROM da_voltage_data_temp WHERE collect_time='{}';".format(assign_time))
    print("第三步，生成并导入数据库数据完毕")

    # 第四步，等待自诊断事件完成
    wait_evevt_done()
    print("第四步，等待自诊断事件完成")

    # 第五步，导出csv
    df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name)
    print("第五步，导出csv完毕")

    # 第六步，检查预期结果
    # 未恢复事件中无“电压数据丢失”事件
    assert "电压数据丢失" not in df_not_recovered["event_name"].to_list()

    # 已恢复事件中上报“电压数据丢失”事件，事件类型为'异常'，事件编码为'51'，事件来源为电压线路:1_1，事件开始时间为删除数据所处时间点，恢复时间与开始时间相同
    df_1 = df_recovered[
        (df_recovered["event_name"] == "电压数据丢失") & (df_recovered["event_type"] == 2) &
        (df_recovered["event_code"] == 51) & (df_recovered["event_source"] == "电压线路：1_1") &
        (df_recovered["start_time"] == assign_time) & (df_recovered["recovery_time"] == recovered_time)]
    # 已恢复事件中新增上报“电压数据丢失”事件，事件来源为电压线路:100_100，事件开始时间为删除数据所处时间点，恢复时间与开始时间相同
    df_2 = df_recovered[
        (df_recovered["event_name"] == "电压数据丢失") & (df_recovered["event_type"] == 2) &
        (df_recovered["event_code"] == 51) & (df_recovered["event_source"] == "电压线路：100_100") &
        (df_recovered["start_time"] == assign_time) & (df_recovered["recovery_time"] == recovered_time)]
    print(df_1)
    print(df_2)

    assert len(df_1) == 1
    assert len(df_2) == 1
    print("第六步，检查预期结果完毕")
    result = "pass"
    # except Exception as e:
    #     print(e)
    #     print("出现异常：{}".format(scene_name))
    # finally:
    write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1401(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 0, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name)
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        # 未恢复事件中上报4条线路的“电压数据丢失”事件，事件来源为4条线路，4个事件的开始时间为最后一条采集数据后1分钟的时间点，无恢复时间
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压数据丢失") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 51) & (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        # 已恢复事件中新增上报“电压数据丢失”事件，事件来源为电压线路:100_100，事件开始时间为删除数据所处时间点，恢复时间与开始时间相同
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压数据丢失") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 51) & (df_not_recovered["event_source"] == "电压线路：2_2") &
            (df_not_recovered["start_time"] == assign_time)]
        df_3 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压数据丢失") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 51) & (df_not_recovered["event_source"] == "电压线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        df_4 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压数据丢失") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 51) & (df_not_recovered["event_source"] == "电压线路：101_101") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)
        print(df_2)
        print(df_3)
        print(df_4)

        assert len(df_1) == 1
        assert len(df_2) == 1
        assert len(df_3) == 1
        assert len(df_4) == 1
        print("第六步，检查预期结果完毕")
        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


# def all_flow_ILAE_1403(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
#                        transformer_parm, time_data):
#     """
#     全流程测试
#     :param ip:
#     :param port:
#     :param username:
#     :param DB_NAME:
#     :param v_arg_list:
#     :param channel_config:
#     :return:
#     """
#     result = "fail"
#     try:
#         print("{}：开始测试".format(scene_name))
#         DB_HOST = ip
#
#         # 第一步，等待1、2、3或者6,7,8的时间开始测试
#         wait_time()
#         print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")
#
#         # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
#         add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
#         add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
#         print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")
#
#         # 第三步，生成并导入数据库数据
#         set_tcp_interface_status(DB_HOST, DB_NAME,
#                                  "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 0, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
#         create_collect_voltage(
#             p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
#                 "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
#         assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
#         print("第三步，生成并导入数据库数据完毕")
#
#         # 第四步，等待自诊断事件完成
#         wait_evevt_done()
#         print("第四步，等待自诊断事件完成")
#
#         # 等待五分钟
#         time.sleep(60)
#         # 打开采集单元
#         set_tcp_interface_status(DB_HOST, DB_NAME,
#                                  "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
#         print("重新打开采集单元")
#         print(datetime.datetime.now())
#         # 第四步，等待自诊断事件完成
#         wait_evevt_done()
#         print("第四步，等待自诊断事件完成")
#
#         # 第五步，导出csv
#         df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name)
#         print("第五步，导出csv完毕")
#         print(df_recovered)
#         print(df_not_recovered)
#
#         # # 第六步，检查预期结果
#         # # 未恢复事件中上报4条线路的“电压数据丢失”事件，事件来源为4条线路，4个事件的开始时间为最后一条采集数据后1分钟的时间点，无恢复时间
#         # df_1 = df_not_recovered[
#         #     (df_not_recovered["event_name"] == "电压数据丢失") & (df_not_recovered["event_type"] == 2) &
#         #     (df_not_recovered["event_code"] == 51) & (df_not_recovered["event_source"] == "电压线路：1_1") &
#         #     (df_not_recovered["start_time"] == assign_time)]
#         # # 已恢复事件中新增上报“电压数据丢失”事件，事件来源为电压线路:100_100，事件开始时间为删除数据所处时间点，恢复时间与开始时间相同
#         # df_2 = df_not_recovered[
#         #     (df_not_recovered["event_name"] == "电压数据丢失") & (df_not_recovered["event_type"] == 2) &
#         #     (df_not_recovered["event_code"] == 51) & (df_not_recovered["event_source"] == "电压线路：2_2") &
#         #     (df_not_recovered["start_time"] == assign_time)]
#         # df_3 = df_not_recovered[
#         #     (df_not_recovered["event_name"] == "电压数据丢失") & (df_not_recovered["event_type"] == 2) &
#         #     (df_not_recovered["event_code"] == 51) & (df_not_recovered["event_source"] == "电压线路：100_100") &
#         #     (df_not_recovered["start_time"] == assign_time)]
#         # df_4 = df_not_recovered[
#         #     (df_not_recovered["event_name"] == "电压数据丢失") & (df_not_recovered["event_type"] == 2) &
#         #     (df_not_recovered["event_code"] == 51) & (df_not_recovered["event_source"] == "电压线路：101_101") &
#         #     (df_not_recovered["start_time"] == assign_time)]
#         # print(df_1)
#         # print(df_2)
#         # print(df_3)
#         # print(df_4)
#         #
#         # assert len(df_1) == 1
#         # assert len(df_2) == 1
#         # assert len(df_3) == 1
#         # assert len(df_4) == 1
#         # print("第六步，检查预期结果完毕")
#         # result = "pass"
#     except Exception as e:
#         print(e)
#         print("出现异常：{}".format(scene_name))
#     finally:
#         write_txt(scene_name + ":" + result + "\r")

def all_flow_ILAE_1404(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 等待1分钟
        time.sleep(60)
        # 删除线路1
        execute_sql("DELETE FROM dv_voltage_channel WHERE channel_num=1;")
        execute_sql("DELETE FROM dv_voltage_line_group_channel WHERE channel_num=1;")

        print("删除线路1")
        print(datetime.datetime.now())
        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name)
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        # 未恢复事件中上报4条线路的“电压数据丢失”事件，事件来源为4条线路，4个事件的开始时间为最后一条采集数据后1分钟的时间点，无恢复时间
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压数据丢失") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 51) & (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        # 已恢复事件中新增上报“电压数据丢失”事件，事件来源为电压线路:100_100，事件开始时间为删除数据所处时间点，恢复时间与开始时间相同
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压数据丢失") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 51) & (df_not_recovered["event_source"] == "电压线路：2_2") &
            (df_not_recovered["start_time"] == assign_time)]
        df_3 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压数据丢失") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 51) & (df_not_recovered["event_source"] == "电压线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        df_4 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压数据丢失") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 51) & (df_not_recovered["event_source"] == "电压线路：101_101") &
            (df_not_recovered["start_time"] == assign_time)]
        df_5 = df_recovered[
            (df_recovered["event_name"] == "电压数据丢失") & (df_recovered["event_type"] == 2) &
            (df_recovered["event_code"] == 51) & (df_recovered["event_source"] == "电压线路：1_1") &
            (df_recovered["start_time"] == assign_time) & (df_recovered["recovery_reason"] == "该配置已经被删除")]
        print(df_1)
        print(df_2)
        print(df_3)
        print(df_4)

        assert len(df_1) == 0
        assert len(df_2) == 1
        assert len(df_3) == 1
        assert len(df_4) == 1
        assert len(df_5) == 1
        print("第六步，检查预期结果完毕")
        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1405(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        assign_time_1s = (datetime.datetime.now().replace(second=0) + datetime.timedelta(seconds=1)).strftime(
            "%Y-%m-%d %H:%M:%S")
        assign_time_1min = (datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=1)).strftime(
            "%Y-%m-%d %H:%M:%S")
        assign_time_20min = (datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=20)).strftime(
            "%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")
        execute_sql(
            "UPDATE da_voltage_data_temp SET collect_time='{}' WHERE collect_time='{}' and channel_num=1;".format(
                assign_time_1s, assign_time_20min))
        execute_sql(
            "UPDATE da_voltage_data_temp SET collect_time='{}' WHERE collect_time='{}' and channel_num=100;".format(
                assign_time_1s, assign_time_20min))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name)
        print("第五步，导出csv完毕")
        # print(df_recovered)
        # print(df_not_recovered)

        # 第六步，检查预期结果
        # 未恢复事件中无“电压数据重复”事件，已恢复事件中上报“电压数据重复”事件，事件类型为'异常'，事件编码为'52'，事件来源为电压线路:1_1，事件开始时间为重复数据所在时间点，恢复时间与开始时间相同
        # 未恢复事件中无“电压数据重复”事件，已恢复事件中上报“电压数据重复”事件，事件来源为电压线路:100_100，事件开始时间为重复数据所在时间点，恢复时间与开始时间相同
        df_1 = df_not_recovered[(df_not_recovered["event_name"] == "电压数据重复")]
        df_2 = df_recovered[
            (df_recovered["event_name"] == "电压数据重复") & (df_recovered["event_type"] == 2) &
            (df_recovered["event_code"] == 52) & (df_recovered["event_source"] == "电压线路：1_1") &
            (df_recovered["start_time"] == assign_time) & (df_recovered["recovery_time"] == assign_time_1min)]
        df_3 = df_recovered[
            (df_recovered["event_name"] == "电压数据重复") & (df_recovered["event_type"] == 2) &
            (df_recovered["event_code"] == 52) & (df_recovered["event_source"] == "电压线路：100_100") &
            (df_recovered["start_time"] == assign_time) & (df_recovered["recovery_time"] == assign_time_1min)]
        # print(df_1)
        # print(df_2)
        # print(df_3)

        assert len(df_1) == 0
        assert len(df_2) == 1
        assert len(df_3) == 1
        print("第六步，检查预期结果完毕")
        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1406_1(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                         transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=9.5,bb_fundamental_amplitude=9.5,cc_fundamental_amplitude=9.5 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name)
        print("第五步，导出csv完毕")
        # print(df_recovered)
        # print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继保仪输出电压确保线路1 A相的采集电压幅值为9.9V，等待自动自诊断后查看自诊断事件列表
        未恢复事件和已恢复事件中均未上报“电压数据幅值异常”事件
        """
        df_1 = df_not_recovered[(df_not_recovered["event_name"] == "电压幅值异常")]
        df_2 = df_recovered[(df_not_recovered["event_name"] == "电压幅值异常")]
        print(df_1)
        print(df_2)

        assert len(df_1) == 0
        assert len(df_2) == 0
        print("第六步，检查预期结果完毕")
        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1406_2(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                         transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=10 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出确保线路1 A相电压幅值为10V，BC相电压幅值为57V，等待自动自诊断后查看自诊断事件列表
        未恢复事件中上报“电压数据幅值异常”事件，事件类型为'异常'，事件编码为'53'，事件来源为电压线路：1_1，事件开始时间为首次采集到电压幅值为10V的时间点，无恢复时间
        """
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压幅值异常") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 53) & (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)

        assert len(df_1) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=55 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤2，修改继保仪输出确保线路1 A相电压幅值55V，等待自动自诊断后查看自诊断事件列表
        未恢复事件中不再上报“电压数据幅值异常”事件，已恢复事件中新增“电压数据幅值异常”事件，事件恢复时间为首次采集到电压幅值为55V的时间点
        """
        df_2 = df_not_recovered[(df_not_recovered["event_name"] == "电压幅值异常")]
        df_3 = df_recovered[
            (df_recovered["event_name"] == "电压幅值异常") & (df_recovered["recovery_time"] == assign_time_1)]
        print(df_2)
        print(df_3)

        assert len(df_2) == 0
        assert len(df_3) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1406_3(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                         transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=54.9 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤3，修改继保仪输出确保线路1 A相电压幅值54.9V，等待自动自诊断后查看自诊断事件列表
        未恢复事件中新增上报“电压数据幅值异常”事件，事件类型为'异常'，事件编码为'53'，事件来源为电压线路：1_1，事件开始时间为首次采集到电压幅值为54.9V的时间点，无恢复时间
        """
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压幅值异常") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 53) & (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)
        assert df_1.iloc[0]["recovery_time"] == None

        assert len(df_1) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=65 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤4，修改继保仪输出确保线路1 A相电压幅值为65V，等待自动自诊断后查看自诊断事件列表
        未恢复事件中不再上报“电压数据幅值异常”事件，已恢复事件中新增“电压数据幅值异常”事件，事件恢复时间为首次采集到电压幅值为65V的时间点
        """
        df_2 = df_not_recovered[(df_not_recovered["event_name"] == "电压幅值异常")]
        df_3 = df_recovered[
            (df_recovered["event_name"] == "电压幅值异常") & (df_recovered["recovery_time"] == assign_time_1)]
        print(df_2)
        print(df_3)

        assert len(df_2) == 0
        assert len(df_3) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1406_4(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                         transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=65.1 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=65.1 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤5，修改继保仪输出确保线路1 A相电压幅值为65.1V，等待自动自诊断后查看自诊断事件列表
        未恢复事件中新增上报“电压数据幅值异常”事件，事件来源为电压线路：1_1，事件开始时间为首次采集到电压幅值为65.1V的时间点，无恢复时间
        修改继保仪输出确保线路2 A相电压幅值为65.1V，等待自动自诊断后查看自诊断事件列表
        未恢复事件中新增上报“电压数据幅值异常”事件，事件来源为电压线路：100_100，事件开始时间为首次采集到电压幅值为65.1V的时间点，无恢复时间
        """
        # 未恢复事件中上报“电压数据幅值异常”事件，事件类型为'异常'，事件编码为'53'，事件来源为电压线路：1_1，事件开始时间为首次采集到电压幅值为10V的时间点，无恢复时间
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压幅值异常") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 53) & (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压幅值异常") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 53) & (df_not_recovered["event_source"] == "电压线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)
        print(df_2)
        print(df_1.iloc[0]["recovery_time"])
        print(df_2.iloc[0]["recovery_time"])

        assert len(df_1) == 1
        assert len(df_2) == 1
        assert df_1.iloc[0]["recovery_time"] == None
        assert df_2.iloc[0]["recovery_time"] == None
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤7，修改继保仪输出确保线路1 A相电压幅值为57V，线路2 A相电压幅值持续保持为65.1V，等待自动自诊断后查看自诊断事件列表
        未恢复事件中只有线路2的“电压数据幅值异常”事件，线路1的“电压数据幅值异常”事件已不在未恢复列表中，已恢复事件中包含线路1的“电压数据幅值异常”事件，事件恢复时间为首次采集到电压幅值为57V的时间点。
        """
        df_3 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压幅值异常") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 53) & (df_not_recovered["event_source"] == "电压线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        df_4 = df_recovered[
            (df_recovered["event_name"] == "电压幅值异常") & (df_recovered["recovery_time"] == assign_time_1) & (
                    df_recovered["event_source"] == "电压线路：1_1")]
        print(df_3)
        print(df_4)

        assert len(df_3) == 1
        assert len(df_4) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1407(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=50 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=50 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继保仪输出电压确保线路1 A相和线路2 A相的采集电压幅值为50V，等待“电压数据幅值异常”事件上报
        线路1和线路2正常上报“电压数据幅值异常”事件
        """
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压幅值异常") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 53) & (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压幅值异常") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 53) & (df_not_recovered["event_source"] == "电压线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)
        print(df_2)

        assert len(df_1) == 1
        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        # 删除线路1
        execute_sql("DELETE FROM dv_voltage_channel WHERE channel_num=1;")
        execute_sql("DELETE FROM dv_voltage_line_group_channel WHERE channel_num=1;")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        删除电压线路1，查看自诊断事件
        已恢复事件中显示线路1_1的电压数据幅值异常事件，恢复时间为删除线路时的时间，恢复原因标注为“该配置已被删除”，未恢复事件中继续显示线路100_100的电压数据幅值异常事件
        """
        df_3 = df_recovered[
            (df_recovered["event_name"] == "电压幅值异常") & (df_recovered["event_type"] == 2) &
            (df_recovered["event_code"] == 53) & (df_recovered["event_source"] == "电压线路：1_1") &
            (df_recovered["start_time"] == assign_time) & (df_recovered["recovery_reason"] == "该配置已经被删除")]
        df_4 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压幅值异常") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 53) & (df_not_recovered["event_source"] == "电压线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_3)
        print(df_4)

        assert len(df_3) == 1
        assert len(df_4) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        # 重新添加线路1
        only_add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        重新添加电压线路1，查看自诊断事件
        线路1重新上报“电压数据幅值异常”事件
        """
        df_5 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压幅值异常") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 53) & (df_not_recovered["event_source"] == "电压线路：1_1")]
        print(df_5)

        assert len(df_5) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1408(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")
        execute_sql(
            "UPDATE da_voltage_data_temp SET bb_fundamental_amplitude=50 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继保仪输出电压确保线路1 B相采集电压幅值为50V，等待自动自诊断查看自诊断事件
        未恢复事件中上报“电压数据幅值异常”事件，事件来源为电压线路：1_1，开始时间为首次采集到电压幅值为50V的时间点
        """
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压幅值异常") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 53) & (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)

        assert len(df_1) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET bb_fundamental_amplitude=60 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出电压确保线路1 B相采集电压幅值为60V，等待自动自诊断查看自诊断事件
        已恢复事件中显示“电压数据幅值异常”事件，事件来源为电压线路：1_1，恢复时间为首次采集到电压幅值为60V的时间点。
        """
        df_2 = df_recovered[
            (df_recovered["event_name"] == "电压幅值异常") & (df_recovered["recovery_time"] == assign_time_1) & (
                    df_recovered["event_source"] == "电压线路：1_1")]
        print(df_2)

        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET bb_fundamental_amplitude=45 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤2，修改继保仪输出电压确保线路1 C相电压采集幅值为45V，等待自动自诊断查看自诊断事件
        未恢复事件中重新上报“电压数据幅值异常”事件，事件来源为电压线路：1_1，开始时间为首次采集到电压幅值为45V的时间点
        """
        df_3 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压幅值异常") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 53) & (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time_1)]
        print(df_3)

        assert len(df_3) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET bb_fundamental_amplitude=58 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_4")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤3，修改继保仪输出电压确保线路1 C相采集电压幅值为58V，等待自动自诊断查看自诊断事件
        已恢复事件中新增显示“电压数据幅值异常”事件，事件来源为电压线路：1_1，恢复时间为首次采集到电压幅值为58V的时间点。
        """
        df_4 = df_recovered[
            (df_recovered["event_name"] == "电压幅值异常") & (df_recovered["recovery_time"] == assign_time_1) & (
                    df_recovered["event_source"] == "电压线路：1_1")]
        print(df_4)

        assert len(df_4) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1409(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_frequency=49 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继保仪输出电压确保线路1 A相的采集电压频率为49Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件和已恢复事件中均未上报“电压频率异常”事件
        """
        df_1 = df_not_recovered[(df_not_recovered["event_name"] == "电压频率异常")]
        df_2 = df_recovered[(df_recovered["event_name"] == "电压频率异常")]
        print(df_1)
        print(df_2)

        assert len(df_1) == 0
        assert len(df_2) == 0
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_frequency=48.9 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出确保线路1 A相电压频率为48.9Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中上报“电压频率异常”事件，事件类型为'异常'，事件编码为'6'，事件来源为电压线路：1_1，事件开始时间为首次采集到电压频率为48.9Hz的时间点，无恢复时间
        """
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压频率异常") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 6) & (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time_1)]
        print(df_2)
        # 无恢复时间
        assert df_2.iloc[0]["recovery_time"] == None
        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_frequency=51 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤2，修改继保仪输出确保线路1 A相电压频率51Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中不再上报“电压频率异常”事件，已恢复事件中新增“电压频率异常”事件，事件恢复时间为首次采集到电压幅值为51Hz的时间点
        """
        df_3 = df_not_recovered[(df_not_recovered["event_name"] == "电压频率异常")]
        df_4 = df_recovered[
            (df_recovered["event_name"] == "电压频率异常") & (df_recovered["event_type"] == 2) &
            (df_recovered["event_code"] == 6) & (df_recovered["event_source"] == "电压线路：1_1") &
            (df_recovered["recovery_time"] == assign_time_1)]
        print(df_3)
        print(df_4)

        assert len(df_3) == 0
        assert len(df_4) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_frequency=51.1 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_frequency=51.1 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_4_5")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤3，修改继保仪输出确保线路1 A相电压频率51.1Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中新增上报“电压频率异常”事件，事件类型为'异常'，事件编码为'6'，事件来源为电压线路：1_1，事件开始时间为首次采集到电压幅值为51.1Hz的时间点，无恢复时间
        修改继保仪输出确保线路2 A相电压频率为51.1Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中新增上报“电压频率异常”事件，事件来源为电压线路：100_100，事件开始时间为首次采集到电压幅值为51.1Hz的时间点，无恢复时间
        """
        df_5 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压频率异常") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 6) & (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time_1)]
        df_6 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压频率异常") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 6) & (df_not_recovered["event_source"] == "电压线路：100_100") &
            (df_not_recovered["start_time"] == assign_time_1)]
        print(df_5)
        print(df_6)

        assert len(df_5) == 1
        assert len(df_6) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_frequency=50 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_6")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤5，修改继保仪输出确保线路1 A相电压频率为50Hz，线路2 A相电压频率持续保持为51.1Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中只有线路2的“电压频率异常”事件，线路1的“电压频率异常”事件已不在未恢复列表中，已恢复事件中新增线路1的“电压频率异常”事件，事件恢复时间为首次采集到电压频率为50Hz的时间点。
        """
        df_7 = df_recovered[
            (df_recovered["event_name"] == "电压频率异常") & (df_recovered["event_type"] == 2) &
            (df_recovered["event_code"] == 6) & (df_recovered["event_source"] == "电压线路：1_1") &
            (df_recovered["recovery_time"] == assign_time_1)]
        df_8 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压频率异常") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 6) & (df_not_recovered["event_source"] == "电压线路：100_100")]
        print(df_7)
        print(df_8)

        assert len(df_7) == 1
        assert len(df_8) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1410(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_frequency=48 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_frequency=48 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继保仪输出电压确保线路1 A相和线路2 A相的采集电压频率为48Hz，等待“电压频率异常”事件上报
        线路1和线路2正常上报“电压频率异常”事件
        """
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压频率异常") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 6) & (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压频率异常") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 6) & (df_not_recovered["event_source"] == "电压线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)
        print(df_2)

        assert len(df_1) == 1
        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        # 删除线路1
        execute_sql("DELETE FROM dv_voltage_channel WHERE channel_num=1;")
        execute_sql("DELETE FROM dv_voltage_line_group_channel WHERE channel_num=1;")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        删除电压线路1，查看自诊断事件
        已恢复事件中显示线路1_1的电压频率异常事件，恢复时间为删除线路时的时间，恢复原因标注为“该配置已被删除”，未恢复事件中继续显示线路100_100的电压频率异常事件
        """
        df_3 = df_recovered[
            (df_recovered["event_name"] == "电压频率异常") & (df_recovered["event_type"] == 2) &
            (df_recovered["event_code"] == 6) & (df_recovered["event_source"] == "电压线路：1_1") &
            (df_recovered["start_time"] == assign_time) & (df_recovered["recovery_reason"] == "该配置已经被删除")]
        df_4 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压频率异常") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 6) & (df_not_recovered["event_source"] == "电压线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_3)
        print(df_4)

        assert len(df_3) == 1
        assert len(df_4) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        # 重新添加线路1
        only_add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        重新添加电压线路1，查看自诊断事件
        线路1重新上报“电压频率异常”事件
        """
        df_5 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压频率异常") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 6) & (df_not_recovered["event_source"] == "电压线路：1_1")]
        print(df_5)

        assert len(df_5) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1411(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")
        execute_sql(
            "UPDATE da_voltage_data_temp SET bb_fundamental_frequency=48 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继保仪输出电压确保线路1 B相采集电压频率为48Hz，等待自动自诊断查看自诊断事件
        未恢复事件中上报“电压频率异常”事件，事件来源为电压线路：1_1，开始时间为首次采集到电压频率为48Hz的时间点
        """
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压频率异常") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 6) & (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)

        assert len(df_1) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET bb_fundamental_frequency=50 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出电压确保线路1 B相采集电压幅值为60V，等待自动自诊断查看自诊断事件
        已恢复事件中显示“电压数据幅值异常”事件，事件来源为电压线路：1_1，恢复时间为首次采集到电压幅值为60V的时间点。
        """
        df_2 = df_recovered[
            (df_recovered["event_name"] == "电压频率异常") & (df_recovered["recovery_time"] == assign_time_1) & (
                    df_recovered["event_source"] == "电压线路：1_1")]
        print(df_2)

        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET cc_fundamental_frequency=52 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤2，修改继保仪输出电压确保线路1 C相电压采集幅值为45V，等待自动自诊断查看自诊断事件
        未恢复事件中重新上报“电压数据幅值异常”事件，事件来源为电压线路：1_1，开始时间为首次采集到电压幅值为45V的时间点
        """
        df_3 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压频率异常") & (df_not_recovered["event_type"] == 2) &
            (df_not_recovered["event_code"] == 6) & (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time_1)]
        print(df_3)

        assert len(df_3) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET cc_fundamental_frequency=50 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_4")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤3，修改继保仪输出电压确保线路1 C相采集电压幅值为58V，等待自动自诊断查看自诊断事件
        已恢复事件中新增显示“电压数据幅值异常”事件，事件来源为电压线路：1_1，恢复时间为首次采集到电压幅值为58V的时间点。
        """
        df_4 = df_recovered[
            (df_recovered["event_name"] == "电压频率异常") & (df_recovered["recovery_time"] == assign_time_1) & (
                    df_recovered["event_source"] == "电压线路：1_1")]
        print(df_4)

        assert len(df_4) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1412(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=10,bb_fundamental_amplitude=10,cc_fundamental_amplitude=10 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出确保线路1 A相电压幅值为10V，BC相电压幅值为57V，等待自动自诊断后查看自诊断事件列表
        未恢复事件中上报“电压数据幅值异常”事件，事件类型为'异常'，事件编码为'53'，事件来源为电压线路：1_1，事件开始时间为首次采集到电压幅值为10V的时间点，无恢复时间
        """
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路停电") & (df_not_recovered["event_type"] == 0) &
            (df_not_recovered["event_code"] == 8) & (df_not_recovered["event_source"] == "电压线路：1_1")]
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路停电") & (df_not_recovered["event_type"] == 0) &
            (df_not_recovered["event_code"] == 8) & (df_not_recovered["event_source"] == "电压线路：100_100")]
        print(df_1)
        print(df_2)

        assert len(df_1) == 0
        assert len(df_2) == 0
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=9.9,bb_fundamental_amplitude=9.9,cc_fundamental_amplitude=9.9 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=9.9,bb_fundamental_amplitude=9.9,cc_fundamental_amplitude=9.9 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤2，修改继保仪输出确保线路1 A相电压幅值55V，等待自动自诊断后查看自诊断事件列表
        未恢复事件中不再上报“电压数据幅值异常”事件，已恢复事件中新增“电压数据幅值异常”事件，事件恢复时间为首次采集到电压幅值为55V的时间点
        """
        df_3 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路停电") & (df_not_recovered["event_type"] == 0) &
            (df_not_recovered["event_code"] == 8) & (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time_1)]
        df_4 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路停电") & (df_not_recovered["event_type"] == 0) &
            (df_not_recovered["event_code"] == 8) & (df_not_recovered["event_source"] == "电压线路：100_100") &
            (df_not_recovered["start_time"] == assign_time_1)]

        print(df_3)
        print(df_4)
        assert df_3.iloc[0]["recovery_time"] == None
        assert df_4.iloc[0]["recovery_time"] == None

        assert len(df_3) == 1
        assert len(df_4) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,bb_fundamental_amplitude=57,cc_fundamental_amplitude=57 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤2，修改继保仪输出确保线路1 A相电压幅值55V，等待自动自诊断后查看自诊断事件列表
        未恢复事件中不再上报“电压数据幅值异常”事件，已恢复事件中新增“电压数据幅值异常”事件，事件恢复时间为首次采集到电压幅值为55V的时间点
        """
        df_5 = df_recovered[
            (df_recovered["event_name"] == "电压线路停电") & (df_recovered["event_type"] == 0) &
            (df_recovered["event_code"] == 8) & (df_recovered["event_source"] == "电压线路：1_1") &
            (df_recovered["recovery_time"] == assign_time_1)]
        df_6 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路停电") & (df_not_recovered["event_type"] == 0) &
            (df_not_recovered["event_code"] == 8) & (df_not_recovered["event_source"] == "电压线路：100_100")]

        print(df_5)
        print(df_6)
        assert len(df_5) == 1
        assert len(df_6) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1413(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=9,bb_fundamental_amplitude=9,cc_fundamental_amplitude=9 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=9,bb_fundamental_amplitude=9,cc_fundamental_amplitude=9 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继保仪输出电压确保线路1 ABC相和线路2 ABC相的采集电压幅值为9Vz，等待“电压频率异常”事件上报
        线路1和线路2正常上报“电压线路停电”事件
        """
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路停电") & (df_not_recovered["event_type"] == 0) &
            (df_not_recovered["event_code"] == 8) & (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路停电") & (df_not_recovered["event_type"] == 0) &
            (df_not_recovered["event_code"] == 8) & (df_not_recovered["event_source"] == "电压线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)
        print(df_2)

        assert len(df_1) == 1
        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        # 删除线路1
        execute_sql("DELETE FROM dv_voltage_channel WHERE channel_num=1;")
        execute_sql("DELETE FROM dv_voltage_line_group_channel WHERE channel_num=1;")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        删除电压线路1，查看自诊断事件
        已恢复事件中显示线路1_1的电压线路停电事件，恢复时间为删除线路时的时间，恢复原因标注为“该配置已被删除”，未恢复事件中继续显示线路100_100的电压线路停电事件
        """
        df_3 = df_recovered[
            (df_recovered["event_name"] == "电压线路停电") & (df_recovered["event_type"] == 0) &
            (df_recovered["event_code"] == 8) & (df_recovered["event_source"] == "电压线路：1_1") &
            (df_recovered["start_time"] == assign_time) & (df_recovered["recovery_reason"] == "该配置已经被删除")]
        df_4 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路停电") & (df_not_recovered["event_type"] == 0) &
            (df_not_recovered["event_code"] == 8) & (df_not_recovered["event_source"] == "电压线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_3)
        print(df_4)

        assert len(df_3) == 1
        assert len(df_4) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        # 重新添加线路1
        only_add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        重新添加电压线路1，查看自诊断事件
        线路1重新上报“电压频率异常”事件
        """
        df_5 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路停电") & (df_not_recovered["event_type"] == 0) &
            (df_not_recovered["event_code"] == 8) & (df_not_recovered["event_source"] == "电压线路：1_1")]
        print(df_5)

        assert len(df_5) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1414(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,bb_fundamental_amplitude=9,cc_fundamental_amplitude=9 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继保仪输出电压确保线路1 BC相采集电压幅值为9V，A相采集电压幅值为57V，等待自动自诊断查看自诊断事件
        线路1不上报“电压线路停电”事件
        """
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路停电") & (df_not_recovered["event_source"] == "电压线路：1_1")]
        print(df_1)

        assert len(df_1) == 0
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=9,bb_fundamental_amplitude=57,cc_fundamental_amplitude=9 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继保仪输出电压确保线路1 AC相采集电压幅值为9V，B相采集电压幅值为57V，等待自动自诊断查看自诊断事件
        线路1不上报“电压线路停电”事件
        """
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路停电") & (df_not_recovered["event_source"] == "电压线路：1_1")]
        print(df_2)

        assert len(df_2) == 0
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=9,bb_fundamental_amplitude=9,cc_fundamental_amplitude=57 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继保仪输出电压确保线路1 AB相采集电压幅值为9V，C相采集电压幅值为57V，等待自动自诊断查看自诊断事件
        线路1不上报“电压线路停电”事件
        """
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路停电") & (df_not_recovered["event_source"] == "电压线路：1_1")]
        print(df_2)

        assert len(df_2) == 0
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1415(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=0,bb_fundamental_phase=-7200,cc_fundamental_phase=7200 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=12,bb_fundamental_phase=-7200,cc_fundamental_phase=7200 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继保仪设置输出线路1A相相位为0°，设置输出线路2 A相相位为0.2°，两路的B、C相位-120°和120°，等待自动自诊断查看自诊断事件
        未恢复事件中新增上报两个“电压线路分列运行”事件，事件开始时间为首次监测到线路1和线路2 A相相位差超过10′的时间点，无恢复时间
        """
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路分列运行") &
            (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路分列运行") &
            (df_not_recovered["event_source"] == "电压线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)
        print(df_2)
        assert df_1.iloc[0]["recovery_time"] == None
        assert df_2.iloc[0]["recovery_time"] == None
        assert len(df_1) == 1
        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=0 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time1))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=6 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        修改线路2的电压等级为110kV，查看自诊断事件
        未恢复事件中不再显示”电压线路分列运行“事件，已恢复事件中新增显示两个“电压线路分列运行”事件，恢复时间为修改线路2电压等级的时间点
        """
        df_3 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路分列运行")]
        df_4 = df_recovered[(df_recovered["event_name"] == "电压线路分列运行") &
                            (df_recovered["event_source"] == "电压线路：1_1") &
                            (df_recovered["recovery_time"] == assign_time1)]
        df_5 = df_recovered[(df_recovered["event_name"] == "电压线路分列运行") &
                            (df_recovered["event_source"] == "电压线路：100_100") &
                            (df_recovered["recovery_time"] == assign_time1)]
        print(df_3)
        print(df_4)
        print(df_5)

        assert len(df_3) == 0
        assert len(df_4) == 1
        assert len(df_5) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=0,bb_fundamental_phase=-7200,cc_fundamental_phase=7200 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time1))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=0,bb_fundamental_phase=-7212,cc_fundamental_phase=7200 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        再次修改线路2的电压等级为220kV，查看自诊断事件
        未恢复事件中重新上报两个“电压线路分列运行”事件
        """
        df_6 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路分列运行") &
                                (df_not_recovered["event_source"] == "电压线路：1_1") &
                                (df_not_recovered["start_time"] == assign_time1)]
        df_7 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路分列运行") &
                                (df_not_recovered["event_source"] == "电压线路：100_100") &
                                (df_not_recovered["start_time"] == assign_time1)]
        print(df_6)
        print(df_7)
        assert df_6.iloc[0]["recovery_time"] == None
        assert df_7.iloc[0]["recovery_time"] == None
        assert len(df_6) == 1
        assert len(df_7) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET bb_fundamental_phase=-7200 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time1))
        execute_sql(
            "UPDATE da_voltage_data_temp SET bb_fundamental_phase=-7206 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_4")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        修改线路2的电压等级为110kV，查看自诊断事件
        未恢复事件中不再显示”电压线路分列运行“事件，已恢复事件中新增显示两个“电压线路分列运行”事件，恢复时间为修改线路2电压等级的时间点
        """
        df_8 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路分列运行")]
        df_9 = df_recovered[(df_recovered["event_name"] == "电压线路分列运行") &
                            (df_recovered["event_source"] == "电压线路：1_1")]
        df_10 = df_recovered[(df_recovered["event_name"] == "电压线路分列运行") &
                             (df_recovered["event_source"] == "电压线路：100_100")]
        print(df_8)
        print(df_9)
        print(df_10)

        assert len(df_8) == 0
        assert len(df_9) == 2
        assert len(df_10) == 2
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=0,bb_fundamental_phase=-7200,cc_fundamental_phase=7200 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time1))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=0,bb_fundamental_phase=-7200,cc_fundamental_phase=7188 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_5")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        再次修改线路2的电压等级为220kV，查看自诊断事件
        未恢复事件中重新上报两个“电压线路分列运行”事件
        """
        df_11 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路分列运行") &
                                 (df_not_recovered["event_source"] == "电压线路：1_1") &
                                 (df_not_recovered["start_time"] == assign_time1)]
        df_12 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路分列运行") &
                                 (df_not_recovered["event_source"] == "电压线路：100_100") &
                                 (df_not_recovered["start_time"] == assign_time1)]
        print(df_11)
        print(df_12)
        assert df_11.iloc[0]["recovery_time"] == None
        assert df_12.iloc[0]["recovery_time"] == None
        assert len(df_11) == 1
        assert len(df_12) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET cc_fundamental_phase=7200 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time1))
        execute_sql(
            "UPDATE da_voltage_data_temp SET cc_fundamental_phase=7206 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_6")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        修改线路2的电压等级为110kV，查看自诊断事件
        未恢复事件中不再显示”电压线路分列运行“事件，已恢复事件中新增显示两个“电压线路分列运行”事件，恢复时间为修改线路2电压等级的时间点
        """
        df_13 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路分列运行")]
        df_14 = df_recovered[(df_recovered["event_name"] == "电压线路分列运行") &
                             (df_recovered["event_source"] == "电压线路：1_1")]
        df_15 = df_recovered[(df_recovered["event_name"] == "电压线路分列运行") &
                             (df_recovered["event_source"] == "电压线路：100_100")]
        print(df_13)
        print(df_14)
        print(df_15)

        assert len(df_13) == 0
        assert len(df_14) == 3
        assert len(df_15) == 3
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1416(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=0,bb_fundamental_phase=-7200,cc_fundamental_phase=7200 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=12,bb_fundamental_phase=-7200,cc_fundamental_phase=7200 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继保仪设置输出线路1A相相位为0°，设置输出线路2 A相相位为0.2°，两路的B、C相位-120°和120°，等待自动自诊断查看自诊断事件
        未恢复事件中新增上报两个“电压线路分列运行”事件，事件开始时间为首次监测到线路1和线路2 A相相位差超过10′的时间点，无恢复时间
        """
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路分列运行") &
            (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路分列运行") &
            (df_not_recovered["event_source"] == "电压线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)
        print(df_2)
        assert df_1.iloc[0]["recovery_time"] == None
        assert df_2.iloc[0]["recovery_time"] == None
        assert len(df_1) == 1
        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql("UPDATE dv_voltage_channel SET channel_level=4 WHERE channel_num=100;")
        execute_sql("UPDATE dv_voltage_line_group_channel SET channel_level=4 WHERE channel_num=100;")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        修改线路2的电压等级为110kV，查看自诊断事件
        未恢复事件中不再显示”电压线路分列运行“事件，已恢复事件中新增显示两个“电压线路分列运行”事件，恢复时间为修改线路2电压等级的时间点
        """
        df_3 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路分列运行")]
        df_4 = df_recovered[(df_recovered["event_name"] == "电压线路分列运行") &
                            (df_recovered["event_source"] == "电压线路：1_1")]
        df_5 = df_recovered[(df_recovered["event_name"] == "电压线路分列运行") &
                            (df_recovered["event_source"] == "电压线路：100_100")]
        print(df_3)
        print(df_4)
        print(df_5)

        assert len(df_3) == 0
        assert len(df_4) == 1
        assert len(df_5) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql("UPDATE dv_voltage_channel SET channel_level=5 WHERE channel_num=100;")
        execute_sql("UPDATE dv_voltage_line_group_channel SET channel_level=5 WHERE channel_num=100;")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        再次修改线路2的电压等级为220kV，查看自诊断事件
        未恢复事件中重新上报两个“电压线路分列运行”事件
        """
        df_6 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路分列运行") &
                                (df_not_recovered["event_source"] == "电压线路：1_1")]
        df_7 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路分列运行") &
                                (df_not_recovered["event_source"] == "电压线路：100_100")]
        print(df_6)
        print(df_7)

        assert len(df_6) == 1
        assert len(df_7) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1417(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=10799,bb_fundamental_phase=3600,cc_fundamental_phase=-3600 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=-10799,bb_fundamental_phase=3600,cc_fundamental_phase=-3600 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继保仪设置输出线路1A相相位为0°，设置输出线路2 A相相位为0.2°，两路的B、C相位-120°和120°，等待自动自诊断查看自诊断事件
        未恢复事件中新增上报两个“电压线路分列运行”事件，事件开始时间为首次监测到线路1和线路2 A相相位差超过10′的时间点，无恢复时间
        """
        df_1 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路分列运行")]
        print(df_1)
        assert len(df_1) == 0
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=10795 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time1))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=-10794 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        修改线路2的电压等级为110kV，查看自诊断事件
        未恢复事件中不再显示”电压线路分列运行“事件，已恢复事件中新增显示两个“电压线路分列运行”事件，恢复时间为修改线路2电压等级的时间点
        """
        df_2 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路分列运行") &
                                (df_not_recovered["event_source"] == "电压线路：1_1")]
        df_3 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路分列运行") &
                                (df_not_recovered["event_source"] == "电压线路：100_100")]
        print(df_2)
        print(df_3)
        assert df_2.iloc[0]["recovery_time"] == None
        assert df_3.iloc[0]["recovery_time"] == None
        assert len(df_2) == 1
        assert len(df_3) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        # 删除线路1
        execute_sql("DELETE FROM dv_voltage_channel WHERE channel_num=1;")
        execute_sql("DELETE FROM dv_voltage_line_group_channel WHERE channel_num=1;")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        再次修改线路2的电压等级为220kV，查看自诊断事件
        未恢复事件中重新上报两个“电压线路分列运行”事件
        """
        df_4 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路分列运行")]
        df_5 = df_recovered[(df_recovered["event_name"] == "电压线路分列运行") &
                            (df_recovered["event_source"] == "电压线路：1_1")]
        df_6 = df_recovered[(df_recovered["event_name"] == "电压线路分列运行") &
                            (df_recovered["event_source"] == "电压线路：100_100")]
        print(df_4)
        print(df_5)
        print(df_6)

        assert len(df_4) == 0
        assert len(df_5) == 1
        assert len(df_6) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        # 重新添加线路1
        only_add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=10795 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_4")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        再次修改线路2的电压等级为220kV，查看自诊断事件
        未恢复事件中重新上报两个“电压线路分列运行”事件
        """
        df_7 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路分列运行") &
                                (df_not_recovered["event_source"] == "电压线路：1_1")]
        df_8 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路分列运行") &
                                (df_not_recovered["event_source"] == "电压线路：100_100")]
        print(df_7)
        print(df_8)
        assert len(df_7) == 1
        assert len(df_8) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1418(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=0,bb_fundamental_amplitude=57,bb_fundamental_phase=-7200,cc_fundamental_amplitude=57,cc_fundamental_phase=7200 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57.0082,aa_fundamental_phase=0.34,bb_fundamental_amplitude=56.9918,bb_fundamental_phase=-7199.66,cc_fundamental_amplitude=56.9918,cc_fundamental_phase=7199.66 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        通过数据库工具向da_voltage_data_temp表中注入当前时间点前5分钟后25分钟共30分钟的两条电压线路的电压采集数据，注入线路1的A相电压幅值为57V，相位为0′，线路2的A相幅值为57.0082V，相位为0.34′，注入线路1的B相电压幅值为57V，相位为-7200′，线路2的B相幅值为56.9918V，相位为-7199.66′，注入线路1的C相电压幅值为57V，相位为7200′，线路2的C相幅值为56.9918V，相位为7199.66′，等待字自动自诊断后查看事件列表
        未恢复事件中上报两个“电压线路同源”事件，事件类型为'提示'，事件编码为'33'，事件来源为电压线路：1_1和100_100，备注列中线路1_1显示“与线路100_100通道线路同源”，线路100_100显示“与线路1_1通道线路同源”，事件开始时间为首次监测到线路1和线路2三相同源的时间点，无恢复时间
        """
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路同源") & (df_not_recovered["event_type"] == 0) &
            (df_not_recovered["event_code"] == 33) & (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路同源") & (df_not_recovered["event_type"] == 0) &
            (df_not_recovered["event_code"] == 33) & (df_not_recovered["event_source"] == "电压线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)
        print(df_2)
        assert df_1.iloc[0]["recovery_time"] == None
        assert df_2.iloc[0]["recovery_time"] == None
        assert len(df_1) == 1
        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=0.35 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        修改线路2的电压等级为110kV，查看自诊断事件
        未恢复事件中不再显示”电压线路分列运行“事件，已恢复事件中新增显示两个“电压线路分列运行”事件，恢复时间为修改线路2电压等级的时间点
        """
        df_3 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路同源")]
        df_4 = df_recovered[(df_recovered["event_name"] == "电压线路同源") &
                            (df_recovered["event_source"] == "电压线路：1_1") &
                            (df_recovered["recovery_time"] == assign_time1)]
        df_5 = df_recovered[(df_recovered["event_name"] == "电压线路同源") &
                            (df_recovered["event_source"] == "电压线路：100_100") &
                            (df_recovered["recovery_time"] == assign_time1)]
        print(df_3)
        print(df_4)
        print(df_5)

        assert len(df_3) == 0
        assert len(df_4) == 1
        assert len(df_5) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1419(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=0,bb_fundamental_amplitude=57,bb_fundamental_phase=-7200,cc_fundamental_amplitude=57,cc_fundamental_phase=7200 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57.0082,aa_fundamental_phase=0.34,bb_fundamental_amplitude=56.9918,bb_fundamental_phase=-7199.66,cc_fundamental_amplitude=56.9918,cc_fundamental_phase=7199.66 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        通过数据库工具向da_voltage_data_temp表中注入当前时间点前5分钟后25分钟共30分钟的两条电压线路的电压采集数据，注入线路1的A相电压幅值为57V，相位为0′，线路2的A相幅值为57.0082V，相位为0.34′，注入线路1的B相电压幅值为57V，相位为-7200′，线路2的B相幅值为56.9918V，相位为-7199.66′，注入线路1的C相电压幅值为57V，相位为7200′，线路2的C相幅值为56.9918V，相位为7199.66′，等待字自动自诊断后查看事件列表
        未恢复事件中上报两个“电压线路同源”事件，事件类型为'提示'，事件编码为'33'，事件来源为电压线路：1_1和100_100，备注列中线路1_1显示“与线路100_100通道线路同源”，线路100_100显示“与线路1_1通道线路同源”，事件开始时间为首次监测到线路1和线路2三相同源的时间点，无恢复时间
        """
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路同源") & (df_not_recovered["event_type"] == 0) &
            (df_not_recovered["event_code"] == 33) & (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路同源") & (df_not_recovered["event_type"] == 0) &
            (df_not_recovered["event_code"] == 33) & (df_not_recovered["event_source"] == "电压线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)
        print(df_2)
        assert df_1.iloc[0]["recovery_time"] == None
        assert df_2.iloc[0]["recovery_time"] == None
        assert len(df_1) == 1
        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql("UPDATE dv_voltage_channel SET channel_level=4 WHERE channel_num=100;")
        execute_sql("UPDATE dv_voltage_line_group_channel SET channel_level=4 WHERE channel_num=100;")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        修改线路2的电压等级为110kV，查看自诊断事件
        未恢复事件中不再显示”电压线路分列运行“事件，已恢复事件中新增显示两个“电压线路分列运行”事件，恢复时间为修改线路2电压等级的时间点
        """
        df_3 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路同源")]
        df_4 = df_recovered[(df_recovered["event_name"] == "电压线路同源") &
                            (df_recovered["event_source"] == "电压线路：1_1")]
        df_5 = df_recovered[(df_recovered["event_name"] == "电压线路同源") &
                            (df_recovered["event_source"] == "电压线路：100_100")]
        print(df_3)
        print(df_4)
        print(df_5)

        assert len(df_3) == 0
        assert len(df_4) == 1
        assert len(df_5) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql("UPDATE dv_voltage_channel SET channel_level=5 WHERE channel_num=100;")
        execute_sql("UPDATE dv_voltage_line_group_channel SET channel_level=5 WHERE channel_num=100;")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        再次修改线路2的电压等级为220kV，查看自诊断事件
        未恢复事件中重新上报两个“电压线路同源”事件
        """
        df_6 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路同源") & (df_not_recovered["event_type"] == 0) &
            (df_not_recovered["event_code"] == 33) & (df_not_recovered["event_source"] == "电压线路：1_1")]
        df_7 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路同源") & (df_not_recovered["event_type"] == 0) &
            (df_not_recovered["event_code"] == 33) & (df_not_recovered["event_source"] == "电压线路：100_100")]
        print(df_6)
        print(df_7)

        assert len(df_6) == 1
        assert len(df_7) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1420(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=0,bb_fundamental_amplitude=57,bb_fundamental_phase=-7200,cc_fundamental_amplitude=57,cc_fundamental_phase=7200 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57.0082,aa_fundamental_phase=0.34,bb_fundamental_amplitude=56.9918,bb_fundamental_phase=-7199.66,cc_fundamental_amplitude=56.9918,cc_fundamental_phase=7199.66 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        通过数据库工具向da_voltage_data_temp表中注入当前时间点前5分钟后25分钟共30分钟的两条电压线路的电压采集数据，注入线路1的A相电压幅值为57V，相位为0′，线路2的A相幅值为57.0082V，相位为0.34′，注入线路1的B相电压幅值为57V，相位为-7200′，线路2的B相幅值为56.9918V，相位为-7199.66′，注入线路1的C相电压幅值为57V，相位为7200′，线路2的C相幅值为56.9918V，相位为7199.66′，等待字自动自诊断后查看事件列表
        未恢复事件中上报两个“电压线路同源”事件，事件类型为'提示'，事件编码为'33'，事件来源为电压线路：1_1和100_100，备注列中线路1_1显示“与线路100_100通道线路同源”，线路100_100显示“与线路1_1通道线路同源”，事件开始时间为首次监测到线路1和线路2三相同源的时间点，无恢复时间
        """
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路同源") & (df_not_recovered["event_type"] == 0) &
            (df_not_recovered["event_code"] == 33) & (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路同源") & (df_not_recovered["event_type"] == 0) &
            (df_not_recovered["event_code"] == 33) & (df_not_recovered["event_source"] == "电压线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)
        print(df_2)
        assert df_1.iloc[0]["recovery_time"] == None
        assert df_2.iloc[0]["recovery_time"] == None
        assert len(df_1) == 1
        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql("DELETE FROM dv_voltage_channel WHERE channel_num=1;")
        execute_sql("DELETE FROM dv_voltage_line_group_channel WHERE channel_num=1;")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        修改线路2的电压等级为110kV，查看自诊断事件
        未恢复事件中不再显示”电压线路分列运行“事件，已恢复事件中新增显示两个“电压线路分列运行”事件，恢复时间为修改线路2电压等级的时间点
        """
        df_3 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路同源")]
        df_4 = df_recovered[(df_recovered["event_name"] == "电压线路同源") &
                            (df_recovered["event_source"] == "电压线路：1_1")]
        df_5 = df_recovered[(df_recovered["event_name"] == "电压线路同源") &
                            (df_recovered["event_source"] == "电压线路：100_100")]
        print(df_3)
        print(df_4)
        print(df_5)

        assert len(df_3) == 0
        assert len(df_4) == 1
        assert len(df_5) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        # 重新添加线路1
        only_add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        再次修改线路2的电压等级为220kV，查看自诊断事件
        未恢复事件中重新上报两个“电压线路同源”事件
        """
        df_6 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路同源") & (df_not_recovered["event_type"] == 0) &
            (df_not_recovered["event_code"] == 33) & (df_not_recovered["event_source"] == "电压线路：1_1")]
        df_7 = df_not_recovered[
            (df_not_recovered["event_name"] == "电压线路同源") & (df_not_recovered["event_type"] == 0) &
            (df_not_recovered["event_code"] == 33) & (df_not_recovered["event_source"] == "电压线路：100_100")]
        print(df_6)
        print(df_7)

        assert len(df_6) == 1
        assert len(df_7) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1421(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=0,bb_fundamental_amplitude=57,bb_fundamental_phase=-7200,cc_fundamental_amplitude=57,cc_fundamental_phase=7200 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57.0086,aa_fundamental_phase=0.34,bb_fundamental_amplitude=56.9915,bb_fundamental_phase=-7199.66,cc_fundamental_amplitude=56.9915,cc_fundamental_phase=7199.66 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        通过数据库工具向da_voltage_data_temp表中注入当前时间点前5分钟后25分钟共30分钟的两条电压线路的电压采集数据，注入线路1的A相电压幅值为57V，相位为0′，线路2的A相幅值为57.0082V，相位为0.34′，注入线路1的B相电压幅值为57V，相位为-7200′，线路2的B相幅值为56.9918V，相位为-7199.66′，注入线路1的C相电压幅值为57V，相位为7200′，线路2的C相幅值为56.9918V，相位为7199.66′，等待字自动自诊断后查看事件列表
        未恢复事件中上报两个“电压线路同源”事件，事件类型为'提示'，事件编码为'33'，事件来源为电压线路：1_1和100_100，备注列中线路1_1显示“与线路100_100通道线路同源”，线路100_100显示“与线路1_1通道线路同源”，事件开始时间为首次监测到线路1和线路2三相同源的时间点，无恢复时间
        """
        df_1 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路同源")]
        print(df_1)
        assert len(df_1) == 0
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=0,bb_fundamental_amplitude=57,bb_fundamental_phase=-7200,cc_fundamental_amplitude=57,cc_fundamental_phase=7200 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time1))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57.0085,aa_fundamental_phase=0.35,bb_fundamental_amplitude=56.9915,bb_fundamental_phase=-7199.66,cc_fundamental_amplitude=56.9915,cc_fundamental_phase=7199.66 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        修改线路2的电压等级为110kV，查看自诊断事件
        未恢复事件中不再显示”电压线路分列运行“事件，已恢复事件中新增显示两个“电压线路分列运行”事件，恢复时间为修改线路2电压等级的时间点
        """
        df_2 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路同源")]
        print(df_2)
        assert len(df_2) == 0
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=0,bb_fundamental_amplitude=57,bb_fundamental_phase=-7200,cc_fundamental_amplitude=57,cc_fundamental_phase=7200 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time1))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57.0085,aa_fundamental_phase=0.34,bb_fundamental_amplitude=56.9914,bb_fundamental_phase=-7199.66,cc_fundamental_amplitude=56.9915,cc_fundamental_phase=7199.66 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        修改线路2的电压等级为110kV，查看自诊断事件
        未恢复事件中不再显示”电压线路分列运行“事件，已恢复事件中新增显示两个“电压线路分列运行”事件，恢复时间为修改线路2电压等级的时间点
        """
        df_3 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路同源")]
        print(df_3)
        assert len(df_3) == 0
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=0,bb_fundamental_amplitude=57,bb_fundamental_phase=-7200,cc_fundamental_amplitude=57,cc_fundamental_phase=7200 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time1))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57.0085,aa_fundamental_phase=0.34,bb_fundamental_amplitude=56.9915,bb_fundamental_phase=-7199.65,cc_fundamental_amplitude=56.9915,cc_fundamental_phase=7199.66 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_4")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        修改线路2的电压等级为110kV，查看自诊断事件
        未恢复事件中不再显示”电压线路分列运行“事件，已恢复事件中新增显示两个“电压线路分列运行”事件，恢复时间为修改线路2电压等级的时间点
        """
        df_4 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路同源")]
        print(df_4)
        assert len(df_4) == 0
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=0,bb_fundamental_amplitude=57,bb_fundamental_phase=-7200,cc_fundamental_amplitude=57,cc_fundamental_phase=7200 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time1))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57.0085,aa_fundamental_phase=0.34,bb_fundamental_amplitude=56.9915,bb_fundamental_phase=-7199.66,cc_fundamental_amplitude=56.9914,cc_fundamental_phase=7199.66 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_5")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        修改线路2的电压等级为110kV，查看自诊断事件
        未恢复事件中不再显示”电压线路分列运行“事件，已恢复事件中新增显示两个“电压线路分列运行”事件，恢复时间为修改线路2电压等级的时间点
        """
        df_5 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路同源")]
        print(df_5)
        assert len(df_5) == 0
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=0,bb_fundamental_amplitude=57,bb_fundamental_phase=-7200,cc_fundamental_amplitude=57,cc_fundamental_phase=7200 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time1))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57.0085,aa_fundamental_phase=0.34,bb_fundamental_amplitude=56.9915,bb_fundamental_phase=-7199.66,cc_fundamental_amplitude=56.9915,cc_fundamental_phase=7199.65 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_6")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        修改线路2的电压等级为110kV，查看自诊断事件
        未恢复事件中不再显示”电压线路分列运行“事件，已恢复事件中新增显示两个“电压线路分列运行”事件，恢复时间为修改线路2电压等级的时间点
        """
        df_6 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路同源")]
        print(df_6)
        assert len(df_6) == 0
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1422(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")

        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=0,bb_fundamental_amplitude=57,bb_fundamental_phase=-8201,cc_fundamental_amplitude=57,cc_fundamental_phase=7199 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=0,bb_fundamental_amplitude=57,bb_fundamental_phase=-7200,cc_fundamental_amplitude=57,cc_fundamental_phase=7200 WHERE channel_num=10 and collect_time>='{}';".format(
                assign_time))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=0,bb_fundamental_amplitude=57,bb_fundamental_phase=-7200,cc_fundamental_amplitude=57,cc_fundamental_phase=7200 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        通过数据库工具向da_voltage_data_temp表中注入当前时间点开始至少1个小时的三条电压线路的电压采集数据，电压幅值均为57V，线路2 3的ABC三相相位为0′、-7200′和7200′，线路1的ABC三相相位为0′、-8201′、7199′，等待自动自诊断后查看事件列表
        未恢复事件中上报一个“接线错误-单通道逆向序”事件，事件类型为‘告警’，事件编码为‘54’，事件来源为电压线路:1_1，事件开始时间为首次监测到线路1 AB相相位差超过1000′的时间点，无恢复时间点
        """
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "接线错误-单通道逆向序") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 54) & (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)
        assert df_1.iloc[0]["recovery_time"] == None
        assert len(df_1) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=0,bb_fundamental_phase=-7200,cc_fundamental_phase=8201 WHERE channel_num=10 and collect_time>='{}';".format(
                assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        修改线路2的电压等级为110kV，查看自诊断事件
        未恢复事件中不再显示”电压线路分列运行“事件，已恢复事件中新增显示两个“电压线路分列运行”事件，恢复时间为修改线路2电压等级的时间点
        """
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "接线错误-单通道逆向序") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 54) & (df_not_recovered["event_source"] == "电压线路：10_10") &
            (df_not_recovered["start_time"] == assign_time1)]
        print(df_2)
        assert df_2.iloc[0]["recovery_time"] == None
        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=-1001,bb_fundamental_phase=-7201,cc_fundamental_phase=7200 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        修改线路2的电压等级为110kV，查看自诊断事件
        未恢复事件中不再显示”电压线路分列运行“事件，已恢复事件中新增显示两个“电压线路分列运行”事件，恢复时间为修改线路2电压等级的时间点
        """
        df_3 = df_not_recovered[
            (df_not_recovered["event_name"] == "接线错误-单通道逆向序") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 54) & (df_not_recovered["event_source"] == "电压线路：100_100") &
            (df_not_recovered["start_time"] == assign_time1)]
        print(df_3)
        assert df_3.iloc[0]["recovery_time"] == None
        assert len(df_3) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=0,bb_fundamental_phase=-7200,cc_fundamental_phase=7200 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time1))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=1,bb_fundamental_phase=-7200,cc_fundamental_phase=7200 WHERE channel_num=10 and collect_time>='{}';".format(
                assign_time1))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=-1,bb_fundamental_phase=-7200,cc_fundamental_phase=7200 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_4")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        修改线路2的电压等级为110kV，查看自诊断事件
        未恢复事件中不再显示”电压线路分列运行“事件，已恢复事件中新增显示两个“电压线路分列运行”事件，恢复时间为修改线路2电压等级的时间点
        """
        df_4 = df_not_recovered[
            (df_not_recovered["event_name"] == "接线错误-单通道逆向序")]
        df_5 = df_recovered[
            (df_recovered["event_name"] == "接线错误-单通道逆向序") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 54) & (df_recovered["event_source"] == "电压线路：1_1")]
        df_6 = df_recovered[
            (df_recovered["event_name"] == "接线错误-单通道逆向序") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 54) & (df_recovered["event_source"] == "电压线路：10_10")]
        df_7 = df_recovered[
            (df_recovered["event_name"] == "接线错误-单通道逆向序") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 54) & (df_recovered["event_source"] == "电压线路：100_100")]
        print(df_4)
        print(df_5)
        print(df_6)
        print(df_7)
        assert len(df_4) == 0
        assert len(df_5) == 1
        assert len(df_6) == 1
        assert len(df_7) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1423(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")

        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=10799,bb_fundamental_amplitude=57,bb_fundamental_phase=3599,cc_fundamental_amplitude=57,cc_fundamental_phase=-3601 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        通过数据库工具向da_voltage_data_temp表中注入当前时间点开始至少1个小时的电压线路1的电压采集数据，电压幅值均为57V，ABC三相相位为10799′、3599′、-3601′，等待自动自诊断后查看事件列表
        不上报“接线错误-单通道逆向序”事件
        """
        df_1 = df_not_recovered[(df_not_recovered["event_name"] == "接线错误-单通道逆向序")]
        print(df_1)
        assert len(df_1) == 0
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=-11801,bb_fundamental_phase=3600,cc_fundamental_phase=-3601 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，从当前时刻开始修改线路1的ABC三相相位为-11801,′、3600′、-3601′，等待自动自诊断后查看事件列表
        未恢复事件中上报一个“接线错误-单通道逆向序”事件，事件类型为‘告警’，事件编码为‘54’，事件来源为电压线路:1_1，事件开始时间为首次监测到线路1 AB相相位差超过1000′的时间点，无恢复时间点
        """
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "接线错误-单通道逆向序") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 54) & (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time1)]
        print(df_2)
        assert df_2.iloc[0]["recovery_time"] == None
        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        # 删除线路1
        execute_sql("DELETE FROM dv_voltage_channel WHERE channel_num=1;")
        execute_sql("DELETE FROM dv_voltage_line_group_channel WHERE channel_num=1;")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        删除电压线路1，查看自诊断事件表
        未恢复事件中不再上报“接线错误-单通道逆向序”事件，已恢复事件中新增显示一条“接线错误-单通道逆向序”事件，事件的恢复时间点为删除电压线路的时间点，
        """
        df_3 = df_not_recovered[(df_not_recovered["event_name"] == "接线错误-单通道逆向序")]
        df_4 = df_recovered[
            (df_recovered["event_name"] == "接线错误-单通道逆向序") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 54) & (df_recovered["event_source"] == "电压线路：1_1")]
        print(df_3)
        print(df_4)
        assert len(df_3) == 0
        assert len(df_4) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        only_add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        execute_sql("DELETE FROM da_voltage_data_temp WHERE channel_num=1 and collect_time<'{}';".format(assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_4")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        重新创建电压线路1，线路通道为1，线路名称为1，电压等级为220kV，通过数据库工具将创建时间点之前的数据删除，等待自动自诊断查看事件列表
        未恢复事件中上报一个“接线错误-单通道逆向序”事件，事件类型为‘告警’，事件编码为‘54’，事件来源为电压线路:1_1，事件开始时间为线路1的创建时间点，无恢复时间点
        """
        df_5 = df_not_recovered[
            (df_not_recovered["event_name"] == "接线错误-单通道逆向序") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 54) & (df_not_recovered["event_source"] == "电压线路：1_1")]
        assert df_5.iloc[0]["recovery_time"] == None
        print(df_5)
        assert len(df_5) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1424(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")

        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=-2701,bb_fundamental_amplitude=57,bb_fundamental_phase=-9901,cc_fundamental_amplitude=57,cc_fundamental_phase=4499 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=2700,bb_fundamental_amplitude=57,bb_fundamental_phase=-4500,cc_fundamental_amplitude=57,cc_fundamental_phase=9900 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        通过数据库工具向da_voltage_data_temp表中注入当前时间点开始至少1个小时的两条电压线路的电压采集数据，电压幅值均为57V，线路2的ABC三相相位为2700′、-4500′和9900′，线路1的ABC三相相位为-2701′、-9901′、4499′，等待自动自诊断后查看事件列表
        未恢复事件中上报两条“接线错误-多通道相序不一致”事件，事件类型为‘告警’，事件编码为‘55’，事件来源为电压线路:1_1、10_10，事件开始时间为首次监测到线路1 与线路2 ABC三相相位均大于5400′的时间点，无恢复时间点
        """
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "接线错误-多通道相序不一致") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 55) & (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "接线错误-多通道相序不一致") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 55) & (df_not_recovered["event_source"] == "电压线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)
        print(df_2)

        assert df_1.iloc[0]["recovery_time"] == None
        assert df_2.iloc[0]["recovery_time"] == None
        assert len(df_1) == 1
        assert len(df_1) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=-2700,bb_fundamental_phase=-9901,cc_fundamental_phase=4499 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，从当前时刻开始修改线路1的ABC三相相位为-11801,′、3600′、-3601′，等待自动自诊断后查看事件列表
        未恢复事件中上报一个“接线错误-单通道逆向序”事件，事件类型为‘告警’，事件编码为‘54’，事件来源为电压线路:1_1，事件开始时间为首次监测到线路1 AB相相位差超过1000′的时间点，无恢复时间点
        """
        df_3 = df_not_recovered[(df_not_recovered["event_name"] == "接线错误-多通道相序不一致")]
        df_4 = df_recovered[(df_recovered["event_name"] == "接线错误-多通道相序不一致") &
                            (df_recovered["event_source"] == "电压线路：1_1") &
                            (df_recovered["recovery_time"] == assign_time1)]
        df_5 = df_recovered[(df_recovered["event_name"] == "接线错误-多通道相序不一致") &
                            (df_recovered["event_source"] == "电压线路：100_100") &
                            (df_recovered["recovery_time"] == assign_time1)]
        print(df_3)
        print(df_4)
        print(df_5)
        assert len(df_3) == 0
        assert len(df_4) == 1
        assert len(df_5) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=-2701,bb_fundamental_phase=-9900,cc_fundamental_phase=4499 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，从当前时刻开始修改线路1的ABC三相相位为-11801,′、3600′、-3601′，等待自动自诊断后查看事件列表
        未恢复事件中上报一个“接线错误-单通道逆向序”事件，事件类型为‘告警’，事件编码为‘54’，事件来源为电压线路:1_1，事件开始时间为首次监测到线路1 AB相相位差超过1000′的时间点，无恢复时间点
        """
        df_6 = df_not_recovered[(df_not_recovered["event_name"] == "接线错误-多通道相序不一致")]
        print(df_6)
        assert len(df_6) == 0
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_phase=-2701,bb_fundamental_phase=-9901,cc_fundamental_phase=4500 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_4")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，从当前时刻开始修改线路1的ABC三相相位为-11801,′、3600′、-3601′，等待自动自诊断后查看事件列表
        未恢复事件中上报一个“接线错误-单通道逆向序”事件，事件类型为‘告警’，事件编码为‘54’，事件来源为电压线路:1_1，事件开始时间为首次监测到线路1 AB相相位差超过1000′的时间点，无恢复时间点
        """
        df_7 = df_not_recovered[(df_not_recovered["event_name"] == "接线错误-多通道相序不一致")]
        print(df_7)
        assert len(df_7) == 0
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1425(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")

        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=-2701,bb_fundamental_amplitude=57,bb_fundamental_phase=-9901,cc_fundamental_amplitude=57,cc_fundamental_phase=4499 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=2700,bb_fundamental_amplitude=57,bb_fundamental_phase=-4500,cc_fundamental_amplitude=57,cc_fundamental_phase=9900 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        通过数据库工具向da_voltage_data_temp表中注入当前时间点开始至少1个小时的两条电压线路的电压采集数据，电压幅值均为57V，线路2的ABC三相相位为2700′、-4500′和9900′，线路1的ABC三相相位为-2701′、-9901′、4499′，等待自动自诊断后查看事件列表
        未恢复事件中上报两条“接线错误-多通道相序不一致”事件，事件类型为‘告警’，事件编码为‘55’，事件来源为电压线路:1_1、10_10，事件开始时间为首次监测到线路1 与线路2 ABC三相相位均大于5400′的时间点，无恢复时间点
        """
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "接线错误-多通道相序不一致") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 55) & (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "接线错误-多通道相序不一致") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 55) & (df_not_recovered["event_source"] == "电压线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)
        print(df_2)
        assert df_1.iloc[0]["recovery_time"] == None
        assert df_2.iloc[0]["recovery_time"] == None
        assert len(df_1) == 1
        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql("UPDATE dv_voltage_channel SET channel_level=4 WHERE channel_num=100;")
        execute_sql("UPDATE dv_voltage_line_group_channel SET channel_level=4 WHERE channel_num=100;")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        修改线路2的电压等级为110kV，等待自动自诊断后查看事件列表
        未恢复事件中仍然显示“接线错误-多通道相序不一致”事件，事件不消失
        """
        df_3 = df_not_recovered[(df_not_recovered["event_name"] == "接线错误-多通道相序不一致")]
        df_4 = df_recovered[
            (df_recovered["event_name"] == "接线错误-多通道相序不一致") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 55) & (df_recovered["event_source"] == "电压线路：1_1")]
        df_5 = df_recovered[
            (df_recovered["event_name"] == "接线错误-多通道相序不一致") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 55) & (df_recovered["event_source"] == "电压线路：100_100")]
        print(df_3)
        print(df_4)
        print(df_5)
        assert len(df_3) == 2
        assert len(df_4) == 0
        assert len(df_5) == 0
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql("UPDATE dv_voltage_channel SET channel_level=5 WHERE channel_num=100;")
        execute_sql("UPDATE dv_voltage_line_group_channel SET channel_level=5 WHERE channel_num=100;")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        修改线路2的电压等级为110kV，等待自动自诊断后查看事件列表
        未恢复事件中不再显示“接线错误-多通道相序不一致”事件，已恢复事件中上报两条“接线错误-多通道相序不一致”事件，恢复时间点为步骤2中修改线路2电压等级的时间点
        """
        df_6 = df_not_recovered[(df_not_recovered["event_name"] == "接线错误-多通道相序不一致")]
        print(df_6)
        assert len(df_6) == 2
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1426(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")

        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=-2701,bb_fundamental_amplitude=57,bb_fundamental_phase=-9901,cc_fundamental_amplitude=57,cc_fundamental_phase=4499 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=2700,bb_fundamental_amplitude=57,bb_fundamental_phase=-4500,cc_fundamental_amplitude=57,cc_fundamental_phase=9900 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        通过数据库工具向da_voltage_data_temp表中注入当前时间点开始至少1个小时的两条电压线路的电压采集数据，电压幅值均为57V，线路2的ABC三相相位为2700′、-4500′和9900′，线路1的ABC三相相位为-2701′、-9901′、4499′，等待自动自诊断后查看事件列表
        未恢复事件中上报两条“接线错误-多通道相序不一致”事件，事件类型为‘告警’，事件编码为‘55’，事件来源为电压线路:1_1、10_10，事件开始时间为首次监测到线路1 与线路2 ABC三相相位均大于5400′的时间点，无恢复时间点
        """
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "接线错误-多通道相序不一致") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 55) & (df_not_recovered["event_source"] == "电压线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "接线错误-多通道相序不一致") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 55) & (df_not_recovered["event_source"] == "电压线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)
        print(df_2)
        assert df_1.iloc[0]["recovery_time"] == None
        assert df_2.iloc[0]["recovery_time"] == None
        assert len(df_1) == 1
        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        # 删除线路1
        execute_sql("DELETE FROM dv_voltage_channel WHERE channel_num=1;")
        execute_sql("DELETE FROM dv_voltage_line_group_channel WHERE channel_num=1;")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        修改线路2的电压等级为110kV，等待自动自诊断后查看事件列表
        未恢复事件中不再显示“接线错误-多通道相序不一致”事件，已恢复事件中上报两条“接线错误-多通道相序不一致”事件，恢复时间点为步骤2中修改线路2电压等级的时间点
        """
        df_3 = df_not_recovered[(df_not_recovered["event_name"] == "接线错误-多通道相序不一致")]
        df_4 = df_recovered[
            (df_recovered["event_name"] == "接线错误-多通道相序不一致") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 55) & (df_recovered["event_source"] == "电压线路：1_1")]
        df_5 = df_recovered[
            (df_recovered["event_name"] == "接线错误-多通道相序不一致") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 55) & (df_recovered["event_source"] == "电压线路：100_100")]
        print(df_3)
        print(df_4)
        print(df_5)
        assert len(df_3) == 0
        assert len(df_4) == 1
        assert len(df_5) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        # 重新添加线路1
        only_add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        execute_sql("DELETE FROM da_voltage_data_temp WHERE channel_num=1 and collect_time<'{}';".format(assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        修改线路2的电压等级为110kV，等待自动自诊断后查看事件列表
        未恢复事件中不再显示“接线错误-多通道相序不一致”事件，已恢复事件中上报两条“接线错误-多通道相序不一致”事件，恢复时间点为步骤2中修改线路2电压等级的时间点
        """
        df_6 = df_not_recovered[
            (df_not_recovered["event_name"] == "接线错误-多通道相序不一致") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 55) & (df_not_recovered["event_source"] == "电压线路：1_1")]
        df_7 = df_not_recovered[
            (df_not_recovered["event_name"] == "接线错误-多通道相序不一致") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 55) & (df_not_recovered["event_source"] == "电压线路：100_100")]
        print(df_6)
        print(df_7)
        assert df_6.iloc[0]["recovery_time"] == None
        assert df_7.iloc[0]["recovery_time"] == None
        assert len(df_6) == 1
        assert len(df_7) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1427(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        create_collect_voltage(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")

        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=5401,bb_fundamental_amplitude=57,bb_fundamental_phase=-1800,cc_fundamental_amplitude=57,cc_fundamental_phase=-9000 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=0,bb_fundamental_amplitude=57,bb_fundamental_phase=7200,cc_fundamental_amplitude=57,cc_fundamental_phase=-7200 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        通过数据库工具向da_voltage_data_temp表中注入当前时间点开始至少1个小时的两条电压线路的电压采集数据，电压幅值均为57V，线路2的ABC三相相位为2700′、-4500′和9900′，线路1的ABC三相相位为-2701′、-9901′、4499′，等待自动自诊断后查看事件列表
        未恢复事件中上报两条“接线错误-多通道相序不一致”事件，事件类型为‘告警’，事件编码为‘55’，事件来源为电压线路:1_1、10_10，事件开始时间为首次监测到线路1 与线路2 ABC三相相位均大于5400′的时间点，无恢复时间点
        """
        df_1 = df_not_recovered[(df_not_recovered["event_name"] == "接线错误-单通道逆向序")]
        df_2 = df_not_recovered[(df_not_recovered["event_name"] == "接线错误-多通道相序不一致")]
        print(df_1)
        print(df_2)
        assert len(df_1) == 1
        assert len(df_2) == 0
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1428(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        now_data = datetime.datetime.now()
        create_collect_voltage(
            p_datetime=(now_data.replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        create_collect_voltage_no_truncate(
            p_datetime=(now_data.replace(second=1) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")

        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=10,aa_fundamental_phase=0,bb_fundamental_amplitude=10,bb_fundamental_phase=-7200,cc_fundamental_amplitude=10,cc_fundamental_phase=7200 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=10,aa_fundamental_phase=0,bb_fundamental_amplitude=10,bb_fundamental_phase=-7200,cc_fundamental_amplitude=10,cc_fundamental_phase=7200 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        通过数据库工具向da_voltage_data_temp表中注入当前时间点开始至少10分钟的两条电压线路的电压采集数据，电压幅值均为10V，ABC三相相位为0′、-7200′、7200′，前5分钟保持每分钟的电压采集数据均有两条，00秒一条，01秒一条，等待自动自诊断后查看事件列表
        未恢复事件中上报“电压数据重复”事件，未上报“电压线路停电”事件
        """
        df_1 = df_not_recovered[(df_not_recovered["event_name"] == "电压数据重复")]
        df_2 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路停电")]
        print(df_1)
        print(df_2)
        assert len(df_1) > 0
        assert len(df_2) == 0
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "DELETE FROM da_voltage_data_temp WHERE EXTRACT(SECOND FROM collect_time) = 1 and collect_time>='{}';".format(
                assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，5分钟后每分钟电压采集数据只有一条，等待自动自诊断后查看事件列表
        未恢复事件中不再上报“电压数据重复”事件，上报“电压线路停电”事件，已恢复事件中上报“电压数据重复”事件
        """
        df_3 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路停电")]
        df_4 = df_recovered[(df_recovered["event_name"] == "电压数据重复")]
        print(df_3)
        print(df_4)
        assert len(df_3) == 0
        assert len(df_4) > 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1429(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        now_data = datetime.datetime.now()
        create_collect_voltage(
            p_datetime=(now_data.replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")

        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_frequency=48,aa_fundamental_amplitude=9,aa_fundamental_phase=0,bb_fundamental_frequency=48,bb_fundamental_amplitude=9,bb_fundamental_phase=-7200,cc_fundamental_frequency=48,cc_fundamental_amplitude=9,cc_fundamental_phase=7200 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_frequency=48,aa_fundamental_amplitude=9,aa_fundamental_phase=0,bb_fundamental_frequency=48,bb_fundamental_amplitude=9,bb_fundamental_phase=-7200,cc_fundamental_frequency=48,cc_fundamental_amplitude=9,cc_fundamental_phase=7200 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        通过数据库工具向da_voltage_data_temp表中注入当前时间点开始至少10分钟的两条电压线路的电压采集数据，电压频率为48Hz，电压幅值均为10V，ABC三相相位为0′、-7200′、7200′，等待自动自诊断后查看事件列表
        未恢复事件中上报“电压线路停电”事件，未上报“电压频率异常”事件
        """
        df_1 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路停电")]
        df_2 = df_not_recovered[(df_not_recovered["event_name"] == "电压频率异常")]
        print(df_1)
        print(df_2)
        assert len(df_1) > 0
        assert len(df_2) == 0
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1430(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        now_data = datetime.datetime.now()
        create_collect_voltage(
            p_datetime=(now_data.replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")

        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_frequency=48,aa_fundamental_amplitude=54,aa_fundamental_phase=0,bb_fundamental_frequency=48,bb_fundamental_amplitude=54,bb_fundamental_phase=-7200,cc_fundamental_frequency=48,cc_fundamental_amplitude=54,cc_fundamental_phase=7200 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_frequency=48,aa_fundamental_amplitude=54,aa_fundamental_phase=0,bb_fundamental_frequency=48,bb_fundamental_amplitude=54,bb_fundamental_phase=-7200,cc_fundamental_frequency=48,cc_fundamental_amplitude=54,cc_fundamental_phase=7200 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        通过数据库工具向da_voltage_data_temp表中注入当前时间点开始至少10分钟的两条电压线路的电压采集数据，电压幅值均为10V，ABC三相相位为0′、-7200′、7200′，前5分钟保持每分钟的电压采集数据均有两条，00秒一条，01秒一条，等待自动自诊断后查看事件列表
        未恢复事件中上报“电压数据重复”事件，未上报“电压线路停电”事件
        """
        df_1 = df_not_recovered[(df_not_recovered["event_name"] == "电压幅值异常")]
        df_2 = df_not_recovered[(df_not_recovered["event_name"] == "电压频率异常")]
        print(df_1)
        print(df_2)
        assert len(df_1) > 0
        assert len(df_2) == 0
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,bb_fundamental_amplitude=57,cc_fundamental_amplitude=57 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time1))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,bb_fundamental_amplitude=57,cc_fundamental_amplitude=57 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，5分钟后每分钟电压采集数据只有一条，等待自动自诊断后查看事件列表
        未恢复事件中不再上报“电压数据重复”事件，上报“电压线路停电”事件，已恢复事件中上报“电压数据重复”事件
        """
        df_3 = df_not_recovered[(df_not_recovered["event_name"] == "电压频率异常")]
        df_4 = df_recovered[(df_recovered["event_name"] == "电压幅值异常")]
        print(df_3)
        print(df_4)
        assert len(df_3) > 1
        assert len(df_4) > 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1431(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        now_data = datetime.datetime.now()
        create_collect_voltage(
            p_datetime=(now_data.replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")

        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_frequency=48,aa_fundamental_amplitude=57,aa_fundamental_phase=0,bb_fundamental_frequency=48,bb_fundamental_amplitude=57,bb_fundamental_phase=-8201,cc_fundamental_frequency=48,cc_fundamental_amplitude=57,cc_fundamental_phase=7199 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_frequency=48,aa_fundamental_amplitude=57,aa_fundamental_phase=0,bb_fundamental_frequency=48,bb_fundamental_amplitude=57,bb_fundamental_phase=-7200,cc_fundamental_frequency=48,cc_fundamental_amplitude=57,cc_fundamental_phase=7200 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        通过数据库工具向da_voltage_data_temp表中注入当前时间点开始至少10分钟的两条电压线路的电压采集数据，电压频率为48Hz，电压幅值均为10V，ABC三相相位为0′、-7200′、7200′，等待自动自诊断后查看事件列表
        未恢复事件中上报“电压线路停电”事件，未上报“电压频率异常”事件
        """
        df_1 = df_not_recovered[(df_not_recovered["event_name"] == "电压频率异常")]
        df_2 = df_not_recovered[(df_not_recovered["event_name"] == "接线错误-单通道逆向序")]
        print(df_1)
        print(df_2)
        assert len(df_1) > 0
        assert len(df_2) == 0
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1432(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        now_data = datetime.datetime.now()
        create_collect_voltage(
            p_datetime=(now_data.replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")

        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=0,bb_fundamental_amplitude=57,bb_fundamental_phase=-8201,cc_fundamental_amplitude=57,cc_fundamental_phase=7199 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=0,bb_fundamental_amplitude=57,bb_fundamental_phase=-8201,cc_fundamental_amplitude=57,cc_fundamental_phase=7199 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        通过数据库工具向da_voltage_data_temp表中注入当前时间点开始至少10分钟的两条电压线路的电压采集数据，电压频率为48Hz，电压幅值均为10V，ABC三相相位为0′、-7200′、7200′，等待自动自诊断后查看事件列表
        未恢复事件中上报“电压线路停电”事件，未上报“电压频率异常”事件
        """
        df_1 = df_not_recovered[(df_not_recovered["event_name"] == "接线错误-单通道逆向序")]
        df_2 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路同源")]
        print(df_1)
        print(df_2)
        assert len(df_1) == 2
        assert len(df_2) == 0
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1433(ip, DB_NAME, v_arg_list, scene_name, channel_config, channel_config_group, algo_config_data,
                       transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_voltage_channel(DB_HOST, DB_NAME, channel_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
        now_data = datetime.datetime.now()
        create_collect_voltage(
            p_datetime=(now_data.replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")

        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=-2701,bb_fundamental_amplitude=57,bb_fundamental_phase=-9901,cc_fundamental_amplitude=57,cc_fundamental_phase=4499 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        execute_sql(
            "UPDATE da_voltage_data_temp SET aa_fundamental_amplitude=57,aa_fundamental_phase=2700,bb_fundamental_amplitude=57,bb_fundamental_phase=-4500,cc_fundamental_amplitude=57,cc_fundamental_phase=9900 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_1")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        通过数据库工具向da_voltage_data_temp表中注入当前时间点开始至少10分钟的两条电压线路的电压采集数据，电压频率为48Hz，电压幅值均为10V，ABC三相相位为0′、-7200′、7200′，等待自动自诊断后查看事件列表
        未恢复事件中上报“电压线路停电”事件，未上报“电压频率异常”事件
        """
        df_1 = df_not_recovered[(df_not_recovered["event_name"] == "接线错误-多通道相序不一致")]
        df_2 = df_not_recovered[(df_not_recovered["event_name"] == "电压线路分列运行")]
        print(df_1)
        print(df_2)
        assert len(df_1) == 2
        assert len(df_2) == 0
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1434(ip, DB_NAME, v_arg_list, scene_name, current_sql_config, channel_config, addr_config,
                       channel_config_group,
                       algo_config_data, transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip
        # 重装站端环境
        initial_data(DB_HOST, port=10088, username="oetsky", password=os_password)

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电流采集单元一', '02', '698', '192.168.10.100', '5000', 1, '2023-08-03 14:42:49', '2023-08-03 14:42:49', '', '1'")
        # add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_current_channel(DB_HOST, DB_NAME, channel_config, addr_config, channel_config_group, algo_config_data,
                            current_sql_config)
        add_current_4_channel(ip, 8082, username)
        skip_4_9_minute()
        create_time = (datetime.datetime.now() + datetime.timedelta(days=-1)).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql("UPDATE dv_current_channel SET create_time='{}';".format(create_time))
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        create_collect_current(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, amp_section=(0.2, 1.1), time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        recovered_time = (datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=1)).strftime(
            "%Y-%m-%d %H:%M:%S")
        execute_sql("DELETE FROM da_current_data_temp WHERE collect_time='{}';".format(assign_time))
        print("第三步，生成并导入数据库数据完毕")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name)
        print("第五步，导出csv完毕")

        # 第六步，检查预期结果
        # 未恢复事件中无“电流数据丢失”事件
        assert "电流数据丢失" not in df_not_recovered["event_name"].to_list()

        # 已恢复事件中上报“电流数据丢失”事件，事件类型为'异常'，事件编码为'61'，事件来源为电流线路:1_1，事件开始时间为删除数据所处时间点，恢复时间与开始时间相同
        df_1 = df_recovered[
            (df_recovered["event_name"] == "电流数据丢失") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 61) & (df_recovered["event_source"] == "电流线路：1_1") &
            (df_recovered["start_time"] == assign_time) & (df_recovered["recovery_time"] == recovered_time)]
        # 已恢复事件中新增上报“电压数据丢失”事件，事件来源为电压线路:100_100，事件开始时间为删除数据所处时间点，恢复时间与开始时间相同
        df_2 = df_recovered[
            (df_recovered["event_name"] == "电流数据丢失") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 61) & (df_recovered["event_source"] == "电流线路：100_100") &
            (df_recovered["start_time"] == assign_time) & (df_recovered["recovery_time"] == recovered_time)]
        print(df_1)
        print(df_2)

        assert len(df_1) == 1
        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")
        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1435(ip, DB_NAME, v_arg_list, scene_name, current_sql_config, channel_config, addr_config,
                       channel_config_group,
                       algo_config_data, transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip
        # 重装站端环境
        initial_data(DB_HOST, port=10088, username="oetsky", password=os_password)

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电流采集单元一', '02', '698', '192.168.10.100', '5000', 0, '2023-08-03 14:42:49', '2023-08-03 14:42:49', '', '1'")
        # add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_current_channel(DB_HOST, DB_NAME, channel_config, addr_config, channel_config_group, algo_config_data,
                            current_sql_config)
        add_current_4_channel(ip, 8082, username)
        skip_4_9_minute()
        create_time = (datetime.datetime.now() + datetime.timedelta(days=-1)).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql("UPDATE dv_current_channel SET create_time='{}';".format(create_time))
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        create_collect_current(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, amp_section=(0.2, 1.1), time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql("DELETE FROM da_current_data_temp WHERE collect_time>='{}';".format(assign_time))
        print("第三步，生成并导入数据库数据完毕")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name)
        print("第五步，导出csv完毕")

        # 第六步，检查预期结果
        # 在配置管理-TCP/IP中，在操作列关闭已打开的电流采集单元，进入主界面-自诊断事件，等待自诊断字自动执行，查看未恢复自诊断事件列表
        # 未恢复事件中上报4条线路的“电流数据丢失”事件，事件来源为4条线路，4个事件的开始时间为最后一条采集数据后1分钟的时间点，无恢复时间
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据丢失") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 61) & (df_not_recovered["event_source"] == "电流线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        # 已恢复事件中新增上报“电压数据丢失”事件，事件来源为电压线路:100_100，事件开始时间为删除数据所处时间点，恢复时间与开始时间相同
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据丢失") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 61) & (df_not_recovered["event_source"] == "电流线路：2_2") &
            (df_not_recovered["start_time"] == assign_time)]
        df_3 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据丢失") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 61) & (df_not_recovered["event_source"] == "电流线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        df_4 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据丢失") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 61) & (df_not_recovered["event_source"] == "电流线路：101_101") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)
        print(df_2)
        print(df_3)
        print(df_4)

        assert len(df_1) == 1
        assert len(df_2) == 1
        assert len(df_3) == 1
        assert len(df_4) == 1
        print("第六步，检查预期结果完毕")
        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1438(ip, DB_NAME, v_arg_list, scene_name, channel_config, addr_config, channel_config_group,
                       algo_config_data, transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电流采集单元一', '02', '698', '192.168.10.100', '5000', 0, '2023-08-03 14:42:49', '2023-08-03 14:42:49', '', '1'")
        # add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_current_channel(DB_HOST, DB_NAME, channel_config, addr_config, channel_config_group, algo_config_data)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        create_collect_current(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, amp_section=(0.2, 1.1), time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name)
        print("第五步，导出csv完毕")

        # 第六步，检查预期结果
        # 在配置管理-TCP/IP中，在操作列关闭已打开的电流采集单元，进入主界面-自诊断事件，等待自诊断字自动执行，查看未恢复自诊断事件列表
        # 未恢复事件中上报4条线路的“电流数据丢失”事件，事件来源为4条线路，4个事件的开始时间为最后一条采集数据后1分钟的时间点，无恢复时间
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据丢失") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 61) & (df_not_recovered["event_source"] == "电流线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        # 已恢复事件中新增上报“电压数据丢失”事件，事件来源为电压线路:100_100，事件开始时间为删除数据所处时间点，恢复时间与开始时间相同
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据丢失") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 61) & (df_not_recovered["event_source"] == "电流线路：2_2") &
            (df_not_recovered["start_time"] == assign_time)]
        df_3 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据丢失") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 61) & (df_not_recovered["event_source"] == "电流线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        df_4 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据丢失") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 61) & (df_not_recovered["event_source"] == "电流线路：101_101") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)
        print(df_2)
        print(df_3)
        print(df_4)

        assert len(df_1) == 1
        assert len(df_2) == 1
        assert len(df_3) == 1
        assert len(df_4) == 1
        print("第六步，检查预期结果完毕")
        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1439(ip, DB_NAME, v_arg_list, scene_name, current_sql_config, channel_config, addr_config,
                       channel_config_group, algo_config_data, transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip
        # 重装站端环境
        initial_data(DB_HOST, port=10088, username="oetsky", password=os_password)

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电流采集单元一', '02', '698', '192.168.10.100', '5000', 0, '2023-08-03 14:42:49', '2023-08-03 14:42:49', '', '1'")
        # add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_current_channel(DB_HOST, DB_NAME, channel_config, addr_config, channel_config_group, algo_config_data,
                            current_sql_config)
        add_current_4_channel(ip, 8082, username)
        skip_4_9_minute()
        create_time = (datetime.datetime.now() + datetime.timedelta(days=-1)).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql("UPDATE dv_current_channel SET create_time='{}';".format(create_time))
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        create_collect_current(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, amp_section=(0.2, 1.1), time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        assign_time_1s = (datetime.datetime.now().replace(second=0) + datetime.timedelta(seconds=1)).strftime(
            "%Y-%m-%d %H:%M:%S")
        assign_time_1min = (datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=1)).strftime(
            "%Y-%m-%d %H:%M:%S")
        assign_time_20min = (datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=20)).strftime(
            "%Y-%m-%d %H:%M:%S")
        print("第三步，生成并导入数据库数据完毕")
        execute_sql(
            "UPDATE da_current_data_temp SET collect_time='{}' WHERE collect_time='{}' and channel_num=1;".format(
                assign_time_1s, assign_time_20min))
        execute_sql(
            "UPDATE da_current_data_temp SET collect_time='{}' WHERE collect_time='{}' and channel_num=100;".format(
                assign_time_1s, assign_time_20min))
        print("第三步，生成并导入数据库数据完毕")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name)
        print("第五步，导出csv完毕")

        # 第六步，检查预期结果
        # 通过数据库工具连接X86数据库，打开da_voltage_data_temp电流数据采集表，将'collect_time'字段倒序，选中时间最近的一条线路通道为1的电流采集数据后幅值，然后添加一条数据并粘贴幅值的数据，修改ID号保持唯一，修改collet_time时间为原时间+1s，等待站端软件自动自诊断，查看自诊断事件列表
        # 未恢复事件中无“电流数据重复”事件，已恢复事件中上报“电流数据重复”事件，事件类型为'异常'，事件编码为'62'，事件来源为电流线路:1_1，事件开始时间为重复数据所在时间点，恢复时间与开始时间相同
        df_1 = df_not_recovered[(df_not_recovered["event_name"] == "电流数据重复")]
        df_2 = df_recovered[
            (df_recovered["event_name"] == "电流数据重复") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 62) & (df_recovered["event_source"] == "电流线路：1_1") &
            (df_recovered["start_time"] == assign_time) & (df_recovered["recovery_time"] == assign_time_1min)]
        df_3 = df_recovered[
            (df_recovered["event_name"] == "电流数据重复") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 62) & (df_recovered["event_source"] == "电流线路：100_100") &
            (df_recovered["start_time"] == assign_time) & (df_recovered["recovery_time"] == assign_time_1min)]
        print(df_1)
        print(df_2)
        print(df_3)

        assert len(df_1) == 0
        assert len(df_2) == 1
        assert len(df_3) == 1
        print("第六步，检查预期结果完毕")
        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1440(ip, DB_NAME, v_arg_list, scene_name, current_sql_config, channel_config, addr_config,
                       channel_config_group, algo_config_data, transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    # try:
    print("{}：开始测试".format(scene_name))
    DB_HOST = ip
    # 初始化站端软件
    initial_data(DB_HOST, port=10088, username="oetsky", password=os_password)

    # 第一步，等待1、2、3或者6,7,8的时间开始测试
    wait_time()
    print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

    # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
    # 添加tcp/ip配置
    set_tcp_interface_status(DB_HOST, DB_NAME,
                             "1, '1', '02', '698', '192.168.20.246', '5000', 1, '2023-08-07 15:45:18', '2023-08-07 15:45:28', '', '1'")
    # 添加电压互感器信息配置
    add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
    # 添加 板卡信息、主控板参数信息、采集板参数信息、采集板模拟量通道排序
    add_current_channel(DB_HOST, DB_NAME, channel_config, addr_config, channel_config_group, algo_config_data,
                        current_sql_config)
    print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

    # 第三步，生成并导入数据库数据
    create_collect_current(
        p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
            "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, amp_section=(0.2, 1.1), time=time_data[1])
    assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
    execute_sql(
        "UPDATE da_current_data_temp SET aa_fundamental_frequency=49 WHERE channel_num=1 and collect_time>='{}';".format(
            assign_time))
    print("第三步，生成并导入数据库数据完毕")

    # 第四步，等待自诊断事件完成
    wait_evevt_done()
    print("第四步，等待自诊断事件完成")

    # 第五步，导出csv
    df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name)
    print("第五步，导出csv完毕")

    # 第六步，检查预期结果
    # 通过数据库工具连接X86数据库，打开da_voltage_data_temp电流数据采集表，将'collect_time'字段倒序，选中时间最近的一条线路通道为1的电流采集数据后幅值，然后添加一条数据并粘贴幅值的数据，修改ID号保持唯一，修改collet_time时间为原时间+1s，等待站端软件自动自诊断，查看自诊断事件列表
    # 未恢复事件中无“电流数据重复”事件，已恢复事件中上报“电流数据重复”事件，事件类型为'异常'，事件编码为'62'，事件来源为电流线路:1_1，事件开始时间为重复数据所在时间点，恢复时间与开始时间相同
    df_1 = df_not_recovered[(df_not_recovered["event_name"] == "电流频率异常")]
    df_2 = df_recovered[(df_recovered["event_name"] == "电流频率异常")]
    print(df_1)
    print(df_2)

    assert len(df_1) == 0
    assert len(df_2) == 0
    print("第六步，检查预期结果完毕")

    # 第一步，等待1、2、3或者6,7,8的时间开始测试
    wait_time()
    assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
    execute_sql(
        "UPDATE da_current_data_temp SET aa_fundamental_frequency=48.9 WHERE channel_num=1 and collect_time>='{}';".format(
            assign_time_1))

    # 第四步，等待自诊断事件完成
    wait_evevt_done()
    print("第四步，等待自诊断事件完成")

    # 第五步，导出csv
    df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
    print("第五步，导出csv完毕")
    print(df_recovered)
    print(df_not_recovered)

    # 第六步，检查预期结果
    """
    继续步骤1，修改继保仪输出确保线路1 A相电流频率为48.9Hz，等待自动自诊断后查看自诊断事件列表
    未恢复事件中上报“电流频率异常”事件，事件类型为'异常'，事件编码为'64'，事件来源为电流线路：1_1，事件开始时间为首次采集到电流频率为48.9Hz的时间点，无恢复时间
    """
    df_3 = df_not_recovered[
        (df_not_recovered["event_name"] == "电流频率异常") & (df_not_recovered["event_type"] == 1) &
        (df_not_recovered["event_code"] == 64) & (df_not_recovered["event_source"] == "电流线路：1_1") &
        (df_not_recovered["start_time"] == assign_time_1)]
    print(df_3)
    # 无恢复时间
    assert df_3.iloc[0]["recovery_time"] == None
    # assert df_3.iloc[1]["recovery_time"] == None
    assert len(df_3) == 1
    print("第六步，检查预期结果完毕")

    # 第一步，等待1、2、3或者6,7,8的时间开始测试
    wait_time()
    assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
    execute_sql(
        "UPDATE da_current_data_temp SET aa_fundamental_frequency=51 WHERE channel_num=1 and collect_time>='{}';".format(
            assign_time_1))

    # 第四步，等待自诊断事件完成
    wait_evevt_done()
    print("第四步，等待自诊断事件完成")

    # 第五步，导出csv
    df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
    print("第五步，导出csv完毕")
    print(df_recovered)
    print(df_not_recovered)

    # 第六步，检查预期结果
    """
    继续步骤1，修改继保仪输出确保线路1 A相电流频率为48.9Hz，等待自动自诊断后查看自诊断事件列表
    未恢复事件中上报“电流频率异常”事件，事件类型为'异常'，事件编码为'64'，事件来源为电流线路：1_1，事件开始时间为首次采集到电流频率为48.9Hz的时间点，无恢复时间
    """
    df_4 = df_not_recovered[(df_not_recovered["event_name"] == "电流频率异常")]
    df_5 = df_recovered[
        (df_recovered["event_name"] == "电流频率异常") & (df_recovered["event_type"] == 1) &
        (df_recovered["event_code"] == 64) & (df_recovered["event_source"] == "电流线路：1_1") &
        (df_recovered["recovery_time"] == assign_time_1)]
    print(df_4)
    print(df_5)
    assert len(df_4) == 0
    assert len(df_5) == 1
    print("第六步，检查预期结果完毕")

    # 第一步，等待1、2、3或者6,7,8的时间开始测试
    wait_time()
    assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
    execute_sql(
        "UPDATE da_current_data_temp SET aa_fundamental_frequency=51.1 WHERE channel_num=1 and collect_time>='{}';".format(
            assign_time_1))

    # 第四步，等待自诊断事件完成
    wait_evevt_done()
    print("第四步，等待自诊断事件完成")

    # 第五步，导出csv
    df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_4")
    print("第五步，导出csv完毕")
    print(df_recovered)
    print(df_not_recovered)

    # 第六步，检查预期结果
    """
    继续步骤1，修改继保仪输出确保线路1 A相电流频率为48.9Hz，等待自动自诊断后查看自诊断事件列表
    未恢复事件中上报“电流频率异常”事件，事件类型为'异常'，事件编码为'64'，事件来源为电流线路：1_1，事件开始时间为首次采集到电流频率为48.9Hz的时间点，无恢复时间
    """
    df_6 = df_not_recovered[
        (df_not_recovered["event_name"] == "电流频率异常") & (df_not_recovered["event_type"] == 1) &
        (df_not_recovered["event_code"] == 64) & (df_not_recovered["event_source"] == "电流线路：1_1") &
        (df_not_recovered["start_time"] == assign_time_1)]
    print(df_6)
    # 无恢复时间
    assert df_6.iloc[0]["recovery_time"] == None
    assert len(df_6) == 1
    print("第六步，检查预期结果完毕")

    # 第一步，等待1、2、3或者6,7,8的时间开始测试
    wait_time()
    assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
    execute_sql(
        "UPDATE da_current_data_temp SET aa_fundamental_frequency=51.1 WHERE channel_num=100 and collect_time>='{}';".format(
            assign_time_1))

    # 第四步，等待自诊断事件完成
    wait_evevt_done()
    print("第四步，等待自诊断事件完成")

    # 第五步，导出csv
    df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_5")
    print("第五步，导出csv完毕")
    print(df_recovered)
    print(df_not_recovered)

    # 第六步，检查预期结果
    """
    修改继保仪输出确保线路2 A相电流频率为51.1Hz，等待自动自诊断后查看自诊断事件列表
    未恢复事件中新增上报“电流频率异常”事件，事件来源为电流线路：100_100，事件开始时间为首次采集到电流幅值为51.1Hz的时间点，无恢复时间
    """
    df_7 = df_not_recovered[
        (df_not_recovered["event_name"] == "电流频率异常") & (df_not_recovered["event_type"] == 1) &
        (df_not_recovered["event_code"] == 64) & (df_not_recovered["event_source"] == "电流线路：100_100") &
        (df_not_recovered["start_time"] == assign_time_1)]
    print(df_7)
    # 无恢复时间
    assert df_7.iloc[0]["recovery_time"] == None
    assert len(df_7) == 1
    print("第六步，检查预期结果完毕")

    # 第一步，等待1、2、3或者6,7,8的时间开始测试
    wait_time()
    assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
    execute_sql(
        "UPDATE da_current_data_temp SET aa_fundamental_frequency=50 WHERE channel_num=1 and collect_time>='{}';".format(
            assign_time_1))

    # 第四步，等待自诊断事件完成
    wait_evevt_done()
    print("第四步，等待自诊断事件完成")

    # 第五步，导出csv
    df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_6")
    print("第五步，导出csv完毕")
    print(df_recovered)
    print(df_not_recovered)

    # 第六步，检查预期结果
    """
    继续步骤5，修改继保仪输出确保线路1 A相电流频率为50Hz，线路2 A相电流频率持续保持为51.1Hz，等待自动自诊断后查看自诊断事件列表
    未恢复事件中只有线路2的“电流频率异常”事件，线路1的“电流频率异常”事件已不在未恢复列表中，已恢复事件中包含线路1的“电流频率异常”事件，事件恢复时间为首次采集到电流频率为50Hz的时间点。
    """
    df_8 = df_not_recovered[
        (df_not_recovered["event_name"] == "电流频率异常") & (df_not_recovered["event_type"] == 1) &
        (df_not_recovered["event_code"] == 64) & (df_not_recovered["event_source"] == "电流线路：100_100")]
    df_9 = df_recovered[
        (df_recovered["event_name"] == "电流频率异常") & (df_recovered["event_type"] == 1) &
        (df_recovered["event_code"] == 64) & (df_recovered["event_source"] == "电流线路：1_1") &
        (df_recovered["recovery_time"] == assign_time_1)]
    print(df_8)
    print(df_9)
    # 无恢复时间
    assert len(df_8) == 1
    assert len(df_9) == 1
    print("第六步，检查预期结果完毕")

    result = "pass"
    # except Exception as e:
    #     print(e)
    #     print("出现异常：{}".format(scene_name))
    # finally:
    write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1441(ip, DB_NAME, v_arg_list, scene_name, current_sql_config, channel_config, addr_config,
                       channel_config_group, algo_config_data, transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip
        # 重装站端环境
        initial_data(DB_HOST, port=10088, username="oetsky", password=os_password)

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电流采集单元一', '02', '698', '192.168.10.100', '5000', 1, '2023-08-03 14:42:49', '2023-08-03 14:42:49', '', '1'")
        # add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_current_channel(DB_HOST, DB_NAME, channel_config, addr_config, channel_config_group, algo_config_data,
                            current_sql_config)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        create_collect_current(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, amp_section=(0.2, 1.1), time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET aa_fundamental_frequency=48 WHERE collect_time>='{}';".format(
                assign_time))
        print("第三步，生成并导入数据库数据完毕")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name)
        print("第五步，导出csv完毕")

        # 第六步，检查预期结果
        # 继保仪输出电流确保线路1 A相和线路2 A相的采集电流频率为48Hz，等待“电流频率异常”事件上报
        # 线路1和线路2正常上报“电流频率异常”事件
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流频率异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 64) & (df_not_recovered["event_source"] == "电流线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流频率异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 64) & (df_not_recovered["event_source"] == "电流线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)
        print(df_2)

        assert len(df_1) == 1
        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        # 删除线路1
        remove_channel(ip, 8082, username, 1)
        # execute_sql("DELETE FROM dv_current_channel WHERE channel_num=1;")
        # execute_sql("DELETE FROM addr_current_channel WHERE channel_num=1;")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        删除电流线路1，查看自诊断事件
        已恢复事件中显示线路1_1的电流频率异常事件，恢复时间为删除线路时的时间，恢复原因标注为“该配置已被删除”，未恢复事件中继续显示线路100_100的电流频率异常事件
        """
        df_3 = df_recovered[
            (df_recovered["event_name"] == "电流频率异常") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 64) & (df_recovered["event_source"] == "电流线路：1_1") &
            (df_recovered["recovery_reason"] == "线路不存在，恢复异常事件")]
        df_4 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流频率异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 64) & (df_not_recovered["event_source"] == "电流线路：100_100")]
        print(df_3)
        print(df_4)
        # 无恢复时间
        assert len(df_3) == 1
        assert len(df_4) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        # 重新添加线路1
        add_current_2_channel(DB_HOST, 8082, username)
        # only_add_current_channel(DB_HOST, DB_NAME, channel_config, addr_config, channel_config_group, algo_config_data)

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出确保线路1 A相电流频率为48.9Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中上报“电流频率异常”事件，事件类型为'异常'，事件编码为'64'，事件来源为电流线路：1_1，事件开始时间为首次采集到电流频率为48.9Hz的时间点，无恢复时间
        """
        df_5 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流频率异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 64) & (df_not_recovered["event_source"] == "电流线路：1_1")]
        print(df_5)
        assert len(df_5) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1442(ip, DB_NAME, v_arg_list, scene_name, current_sql_config, channel_config, addr_config,
                       channel_config_group,
                       algo_config_data, transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip
        # 重装站端环境
        initial_data(DB_HOST, port=10088, username="oetsky", password=os_password)

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电流采集单元一', '02', '698', '192.168.10.100', '5000', 1, '2023-08-03 14:42:49', '2023-08-03 14:42:49', '', '1'")
        # add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_current_channel(DB_HOST, DB_NAME, channel_config, addr_config, channel_config_group, algo_config_data,
                            current_sql_config)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        create_collect_current(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, amp_section=(0.2, 1.1), time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET bb_fundamental_frequency=48 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        print("第三步，生成并导入数据库数据完毕")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name)
        print("第五步，导出csv完毕")

        # 第六步，检查预期结果
        # 继保仪输出电流确保线路1 A相和线路2 A相的采集电流频率为48Hz，等待“电流频率异常”事件上报
        # 线路1和线路2正常上报“电流频率异常”事件
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流频率异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 64) & (df_not_recovered["event_source"] == "电流线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)

        assert len(df_1) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET bb_fundamental_frequency=50 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出电流确保线路1 B相采集电流幅值为50Hz，等待自动自诊断查看自诊断事件
        已恢复事件中显示“电流频率异常”事件，事件来源为电流线路：1_1，恢复时间为首次采集到电流频率为50Hz的时间点。
        """
        df_2 = df_recovered[
            (df_recovered["event_name"] == "电流频率异常") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 64) & (df_recovered["event_source"] == "电流线路：1_1") &
            (df_recovered["recovery_time"] == assign_time_1)]
        print(df_2)
        # 无恢复时间
        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET cc_fundamental_frequency=52 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出确保线路1 A相电流频率为48.9Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中上报“电流频率异常”事件，事件类型为'异常'，事件编码为'64'，事件来源为电流线路：1_1，事件开始时间为首次采集到电流频率为48.9Hz的时间点，无恢复时间
        """
        df_3 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流频率异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 64) & (df_not_recovered["event_source"] == "电流线路：1_1") &
            (df_not_recovered["start_time"] == assign_time_1)]
        print(df_3)

        assert len(df_3) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET cc_fundamental_frequency=50 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_4")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        删除电流线路1，查看自诊断事件
        已恢复事件中显示线路1_1的电流频率异常事件，恢复时间为删除线路时的时间，恢复原因标注为“该配置已被删除”，未恢复事件中继续显示线路100_100的电流频率异常事件
        """
        df_4 = df_recovered[
            (df_recovered["event_name"] == "电流频率异常") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 64) & (df_recovered["event_source"] == "电流线路：1_1") &
            (df_recovered["recovery_time"] == assign_time_1)]
        print(df_4)
        # 无恢复时间
        assert len(df_4) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1443(ip, DB_NAME, v_arg_list, scene_name, current_sql_config, channel_config, addr_config,
                       channel_config_group,
                       algo_config_data, transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip
        # 重装站端环境
        initial_data(DB_HOST, port=10088, username="oetsky", password=os_password)

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电流采集单元一', '02', '698', '192.168.10.100', '5000', 1, '2023-08-03 14:42:49', '2023-08-03 14:42:49', '', '1'")
        # add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_current_channel(DB_HOST, DB_NAME, channel_config, addr_config, channel_config_group, algo_config_data,
                            current_sql_config)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        create_collect_current(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, amp_section=(3, 4), time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET aa_fundamental_frequency=49 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        print("第三步，生成并导入数据库数据完毕")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name)
        print("第五步，导出csv完毕")

        # 第六步，检查预期结果
        # 通过数据库工具连接X86数据库，打开da_voltage_data_temp电流数据采集表，将'collect_time'字段倒序，选中时间最近的一条线路通道为1的电流采集数据后幅值，然后添加一条数据并粘贴幅值的数据，修改ID号保持唯一，修改collet_time时间为原时间+1s，等待站端软件自动自诊断，查看自诊断事件列表
        # 未恢复事件中无“电流数据重复”事件，已恢复事件中上报“电流数据重复”事件，事件类型为'异常'，事件编码为'62'，事件来源为电流线路:1_1，事件开始时间为重复数据所在时间点，恢复时间与开始时间相同
        df_1 = df_not_recovered[(df_not_recovered["event_name"] == "电流频率异常")]
        df_2 = df_recovered[(df_recovered["event_name"] == "电流频率异常")]
        print(df_1)
        print(df_2)

        assert len(df_1) == 0
        assert len(df_2) == 0
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET aa_fundamental_frequency=48.9 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出确保线路1 A相电流频率为48.9Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中上报“电流频率异常”事件，事件类型为'异常'，事件编码为'64'，事件来源为电流线路：1_1，事件开始时间为首次采集到电流频率为48.9Hz的时间点，无恢复时间
        """
        df_3 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流频率异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 64) & (df_not_recovered["event_source"] == "电流线路：1_1") &
            (df_not_recovered["start_time"] == assign_time_1)]
        print(df_3)
        # 无恢复时间
        assert df_3.iloc[0]["recovery_time"] == None
        assert len(df_3) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET aa_fundamental_frequency=51 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出确保线路1 A相电流频率为48.9Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中上报“电流频率异常”事件，事件类型为'异常'，事件编码为'64'，事件来源为电流线路：1_1，事件开始时间为首次采集到电流频率为48.9Hz的时间点，无恢复时间
        """
        df_4 = df_not_recovered[(df_not_recovered["event_name"] == "电流频率异常")]
        df_5 = df_recovered[
            (df_recovered["event_name"] == "电流频率异常") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 64) & (df_recovered["event_source"] == "电流线路：1_1") &
            (df_recovered["recovery_time"] == assign_time_1)]
        print(df_4)
        print(df_5)
        assert len(df_4) == 0
        assert len(df_5) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET aa_fundamental_frequency=51.1 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_4")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出确保线路1 A相电流频率为48.9Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中上报“电流频率异常”事件，事件类型为'异常'，事件编码为'64'，事件来源为电流线路：1_1，事件开始时间为首次采集到电流频率为48.9Hz的时间点，无恢复时间
        """
        df_6 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流频率异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 64) & (df_not_recovered["event_source"] == "电流线路：1_1") &
            (df_not_recovered["start_time"] == assign_time_1)]
        print(df_6)
        # 无恢复时间
        assert df_6.iloc[0]["recovery_time"] == None
        assert len(df_6) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET aa_fundamental_frequency=51.1 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_5")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        修改继保仪输出确保线路2 A相电流频率为51.1Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中新增上报“电流频率异常”事件，事件来源为电流线路：100_100，事件开始时间为首次采集到电流幅值为51.1Hz的时间点，无恢复时间
        """
        df_7 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流频率异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 64) & (df_not_recovered["event_source"] == "电流线路：100_100") &
            (df_not_recovered["start_time"] == assign_time_1)]
        print(df_7)
        # 无恢复时间
        assert df_7.iloc[0]["recovery_time"] == None
        assert len(df_7) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET aa_fundamental_frequency=50 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_6")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤5，修改继保仪输出确保线路1 A相电流频率为50Hz，线路2 A相电流频率持续保持为51.1Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中只有线路2的“电流频率异常”事件，线路1的“电流频率异常”事件已不在未恢复列表中，已恢复事件中包含线路1的“电流频率异常”事件，事件恢复时间为首次采集到电流频率为50Hz的时间点。
        """
        df_8 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流频率异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 64) & (df_not_recovered["event_source"] == "电流线路：100_100")]
        df_9 = df_recovered[
            (df_recovered["event_name"] == "电流频率异常") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 64) & (df_recovered["event_source"] == "电流线路：1_1") &
            (df_recovered["recovery_time"] == assign_time_1)]
        print(df_8)
        print(df_9)
        # 无恢复时间
        assert len(df_8) == 1
        assert len(df_9) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1444(ip, DB_NAME, v_arg_list, scene_name, current_sql_config, channel_config, addr_config,
                       channel_config_group,
                       algo_config_data, transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip
        # 重装站端环境
        initial_data(DB_HOST, port=10088, username="oetsky", password=os_password)

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电流采集单元一', '02', '698', '192.168.10.100', '5000', 1, '2023-08-03 14:42:49', '2023-08-03 14:42:49', '', '1'")
        # add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_current_channel(DB_HOST, DB_NAME, channel_config, addr_config, channel_config_group, algo_config_data,
                            current_sql_config)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        create_collect_current(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, amp_section=(3, 4), time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET aa_fundamental_frequency=48 WHERE collect_time>='{}';".format(
                assign_time))
        print("第三步，生成并导入数据库数据完毕")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name)
        print("第五步，导出csv完毕")

        # 第六步，检查预期结果
        # 继保仪输出电流确保线路1 A相和线路2 A相的采集电流频率为48Hz，等待“电流频率异常”事件上报
        # 线路1和线路2正常上报“电流频率异常”事件
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流频率异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 64) & (df_not_recovered["event_source"] == "电流线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流频率异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 64) & (df_not_recovered["event_source"] == "电流线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)
        print(df_2)

        assert len(df_1) == 1
        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        # 删除线路1
        remove_channel(ip, 8082, username, 1)
        # execute_sql("DELETE FROM dv_current_channel WHERE channel_num=1;")
        # execute_sql("DELETE FROM addr_current_channel WHERE channel_num=1;")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        删除电流线路1，查看自诊断事件
        已恢复事件中显示线路1_1的电流频率异常事件，恢复时间为删除线路时的时间，恢复原因标注为“该配置已被删除”，未恢复事件中继续显示线路100_100的电流频率异常事件
        """
        df_3 = df_recovered[
            (df_recovered["event_name"] == "电流频率异常") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 64) & (df_recovered["event_source"] == "电流线路：1_1") &
            (df_recovered["recovery_reason"] == "线路不存在，恢复异常事件")]
        df_4 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流频率异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 64) & (df_not_recovered["event_source"] == "电流线路：100_100")]
        print(df_3)
        print(df_4)
        # 无恢复时间
        assert len(df_3) == 1
        assert len(df_4) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        # 重新添加线路1
        add_current_2_channel(DB_HOST, 8082, username)
        # only_add_current_channel(DB_HOST, DB_NAME, channel_config, addr_config, channel_config_group, algo_config_data)

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出确保线路1 A相电流频率为48.9Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中上报“电流频率异常”事件，事件类型为'异常'，事件编码为'64'，事件来源为电流线路：1_1，事件开始时间为首次采集到电流频率为48.9Hz的时间点，无恢复时间
        """
        df_5 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流频率异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 64) & (df_not_recovered["event_source"] == "电流线路：1_1")]
        print(df_5)
        assert len(df_5) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1445(ip, DB_NAME, v_arg_list, scene_name, current_sql_config, channel_config, addr_config,
                       channel_config_group, algo_config_data, transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip
        # 重装站端环境
        initial_data(DB_HOST, port=10088, username="oetsky", password=os_password)

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电流采集单元一', '02', '698', '192.168.10.100', '5000', 1, '2023-08-03 14:42:49', '2023-08-03 14:42:49', '', '1'")
        # add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_current_channel(DB_HOST, DB_NAME, channel_config, addr_config, channel_config_group, algo_config_data,
                            current_sql_config)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        create_collect_current(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, amp_section=(3, 4), time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET bb_fundamental_frequency=48 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        print("第三步，生成并导入数据库数据完毕")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name)
        print("第五步，导出csv完毕")

        # 第六步，检查预期结果
        # 继保仪输出电流确保线路1 A相和线路2 A相的采集电流频率为48Hz，等待“电流频率异常”事件上报
        # 线路1和线路2正常上报“电流频率异常”事件
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流频率异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 64) & (df_not_recovered["event_source"] == "电流线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)

        assert len(df_1) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET bb_fundamental_frequency=50 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出电流确保线路1 B相采集电流幅值为50Hz，等待自动自诊断查看自诊断事件
        已恢复事件中显示“电流频率异常”事件，事件来源为电流线路：1_1，恢复时间为首次采集到电流频率为50Hz的时间点。
        """
        df_2 = df_recovered[
            (df_recovered["event_name"] == "电流频率异常") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 64) & (df_recovered["event_source"] == "电流线路：1_1") &
            (df_recovered["recovery_time"] == assign_time_1)]
        print(df_2)
        # 无恢复时间
        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET cc_fundamental_frequency=52 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出确保线路1 A相电流频率为48.9Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中上报“电流频率异常”事件，事件类型为'异常'，事件编码为'64'，事件来源为电流线路：1_1，事件开始时间为首次采集到电流频率为48.9Hz的时间点，无恢复时间
        """
        df_3 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流频率异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 64) & (df_not_recovered["event_source"] == "电流线路：1_1") &
            (df_not_recovered["start_time"] == assign_time_1)]
        print(df_3)

        assert len(df_3) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET cc_fundamental_frequency=50 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_4")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        删除电流线路1，查看自诊断事件
        已恢复事件中显示线路1_1的电流频率异常事件，恢复时间为删除线路时的时间，恢复原因标注为“该配置已被删除”，未恢复事件中继续显示线路100_100的电流频率异常事件
        """
        df_4 = df_recovered[
            (df_recovered["event_name"] == "电流频率异常") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 64) & (df_recovered["event_source"] == "电流线路：1_1") &
            (df_recovered["recovery_time"] == assign_time_1)]
        print(df_4)
        # 无恢复时间
        assert len(df_4) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1446(ip, DB_NAME, v_arg_list, scene_name, current_sql_config, channel_config, addr_config,
                       channel_config_group, algo_config_data, transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip
        # 重装站端环境
        initial_data(DB_HOST, port=10088, username="oetsky", password=os_password)

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        set_sql_current_1A(ip, DB_NAME, min=0.2, max=1.1)
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电流采集单元一', '02', '698', '192.168.10.100', '5000', 1, '2023-08-03 14:42:49', '2023-08-03 14:42:49', '', '1'")
        # add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_current_channel(DB_HOST, DB_NAME, channel_config, addr_config, channel_config_group, algo_config_data,
                            current_sql_config)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        create_collect_current(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, amp_section=(0.2, 1.1), time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET aa_fundamental_amplitude=0.2 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        print("第三步，生成并导入数据库数据完毕")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name)
        print("第五步，导出csv完毕")

        # 第六步，检查预期结果
        # 通过数据库工具连接X86数据库，打开da_voltage_data_temp电流数据采集表，将'collect_time'字段倒序，选中时间最近的一条线路通道为1的电流采集数据后幅值，然后添加一条数据并粘贴幅值的数据，修改ID号保持唯一，修改collet_time时间为原时间+1s，等待站端软件自动自诊断，查看自诊断事件列表
        # 未恢复事件中无“电流数据重复”事件，已恢复事件中上报“电流数据重复”事件，事件类型为'异常'，事件编码为'62'，事件来源为电流线路:1_1，事件开始时间为重复数据所在时间点，恢复时间与开始时间相同
        df_1 = df_not_recovered[(df_not_recovered["event_name"] == "电流数据幅值异常")]
        df_2 = df_recovered[(df_recovered["event_name"] == "电流数据幅值异常")]
        print(df_1)
        print(df_2)

        assert len(df_1) == 0
        assert len(df_2) == 0
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET aa_fundamental_amplitude=0.1 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出确保线路1 A相电流频率为48.9Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中上报“电流频率异常”事件，事件类型为'异常'，事件编码为'64'，事件来源为电流线路：1_1，事件开始时间为首次采集到电流频率为48.9Hz的时间点，无恢复时间
        """
        df_3 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据幅值异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 63) & (df_not_recovered["event_source"] == "电流线路：1_1") &
            (df_not_recovered["start_time"] == assign_time_1)]
        print(df_3)
        # 无恢复时间
        assert df_3.iloc[0]["recovery_time"] == None
        assert len(df_3) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET aa_fundamental_amplitude=1.1 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出确保线路1 A相电流频率为48.9Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中上报“电流频率异常”事件，事件类型为'异常'，事件编码为'64'，事件来源为电流线路：1_1，事件开始时间为首次采集到电流频率为48.9Hz的时间点，无恢复时间
        """
        df_4 = df_not_recovered[(df_not_recovered["event_name"] == "电流数据幅值异常")]
        df_5 = df_recovered[
            (df_recovered["event_name"] == "电流数据幅值异常") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 63) & (df_recovered["event_source"] == "电流线路：1_1") &
            (df_recovered["recovery_time"] == assign_time_1)]
        print(df_4)
        print(df_5)
        assert len(df_4) == 0
        assert len(df_5) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET aa_fundamental_amplitude=1.2 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_4")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出确保线路1 A相电流频率为48.9Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中上报“电流频率异常”事件，事件类型为'异常'，事件编码为'64'，事件来源为电流线路：1_1，事件开始时间为首次采集到电流频率为48.9Hz的时间点，无恢复时间
        """
        df_6 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据幅值异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 63) & (df_not_recovered["event_source"] == "电流线路：1_1") &
            (df_not_recovered["start_time"] == assign_time_1)]
        print(df_6)
        # 无恢复时间
        assert df_6.iloc[0]["recovery_time"] == None
        assert len(df_6) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET aa_fundamental_amplitude=1.2 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_5")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        修改继保仪输出确保线路2 A相电流频率为51.1Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中新增上报“电流频率异常”事件，事件来源为电流线路：100_100，事件开始时间为首次采集到电流幅值为51.1Hz的时间点，无恢复时间
        """
        df_7 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据幅值异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 63) & (df_not_recovered["event_source"] == "电流线路：100_100") &
            (df_not_recovered["start_time"] == assign_time_1)]
        print(df_7)
        # 无恢复时间
        assert df_7.iloc[0]["recovery_time"] == None
        assert len(df_7) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET aa_fundamental_amplitude=1 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_6")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤5，修改继保仪输出确保线路1 A相电流频率为50Hz，线路2 A相电流频率持续保持为51.1Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中只有线路2的“电流频率异常”事件，线路1的“电流频率异常”事件已不在未恢复列表中，已恢复事件中包含线路1的“电流频率异常”事件，事件恢复时间为首次采集到电流频率为50Hz的时间点。
        """
        df_8 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据幅值异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 63) & (df_not_recovered["event_source"] == "电流线路：100_100")]
        df_9 = df_recovered[
            (df_recovered["event_name"] == "电流数据幅值异常") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 63) & (df_recovered["event_source"] == "电流线路：1_1") &
            (df_recovered["recovery_time"] == assign_time_1)]
        print(df_8)
        print(df_9)
        # 无恢复时间
        assert len(df_8) == 1
        assert len(df_9) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        set_sql_current_1A(ip, DB_NAME, min=0, max=1.25)
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1447(ip, DB_NAME, v_arg_list, scene_name, current_sql_config, channel_config, addr_config,
                       channel_config_group, algo_config_data, transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip
        # 重装站端环境
        initial_data(DB_HOST, port=10088, username="oetsky", password=os_password)

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        set_sql_current_1A(ip, DB_NAME, min=0.2, max=1.1)
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电流采集单元一', '02', '698', '192.168.10.100', '5000', 1, '2023-08-03 14:42:49', '2023-08-03 14:42:49', '', '1'")
        # add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_current_channel(DB_HOST, DB_NAME, channel_config, addr_config, channel_config_group, algo_config_data,
                            current_sql_config)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        create_collect_current(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, amp_section=(0.2, 1.1), time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET aa_fundamental_amplitude=1.2 WHERE collect_time>='{}';".format(
                assign_time))
        print("第三步，生成并导入数据库数据完毕")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name)
        print("第五步，导出csv完毕")

        # 第六步，检查预期结果
        # 继保仪输出电流确保线路1 A相和线路2 A相的采集电流频率为48Hz，等待“电流频率异常”事件上报
        # 线路1和线路2正常上报“电流频率异常”事件
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据幅值异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 63) & (df_not_recovered["event_source"] == "电流线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据幅值异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 63) & (df_not_recovered["event_source"] == "电流线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)
        print(df_2)

        assert len(df_1) == 1
        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        # 删除线路1
        remove_channel(ip, 8082, username, 1)
        # execute_sql("DELETE FROM dv_current_channel WHERE channel_num=1;")
        # execute_sql("DELETE FROM addr_current_channel WHERE channel_num=1;")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        删除电流线路1，查看自诊断事件
        已恢复事件中显示线路1_1的电流频率异常事件，恢复时间为删除线路时的时间，恢复原因标注为“该配置已被删除”，未恢复事件中继续显示线路100_100的电流频率异常事件
        """
        df_3 = df_recovered[
            (df_recovered["event_name"] == "电流数据幅值异常") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 63) & (df_recovered["event_source"] == "电流线路：1_1") &
            (df_recovered["recovery_reason"] == "线路不存在，恢复异常事件")]
        df_4 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据幅值异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 63) & (df_not_recovered["event_source"] == "电流线路：100_100")]
        print(df_3)
        print(df_4)
        # 无恢复时间
        assert len(df_3) == 1
        assert len(df_4) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        # 重新添加线路1
        add_current_2_channel(DB_HOST, 8082, username)
        # only_add_current_channel(DB_HOST, DB_NAME, channel_config, addr_config, channel_config_group, algo_config_data)

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出确保线路1 A相电流频率为48.9Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中上报“电流频率异常”事件，事件类型为'异常'，事件编码为'64'，事件来源为电流线路：1_1，事件开始时间为首次采集到电流频率为48.9Hz的时间点，无恢复时间
        """
        df_5 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据幅值异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 63) & (df_not_recovered["event_source"] == "电流线路：1_1")]
        print(df_5)
        assert len(df_5) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        set_sql_current_1A(ip, DB_NAME, min=0, max=1.25)
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1448(ip, DB_NAME, v_arg_list, scene_name, current_sql_config, channel_config, addr_config,
                       channel_config_group,
                       algo_config_data, transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip
        # 重装站端环境
        initial_data(DB_HOST, port=10088, username="oetsky", password=os_password)

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        set_sql_current_1A(ip, DB_NAME, min=0.2, max=1.1)
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电流采集单元一', '02', '698', '192.168.10.100', '5000', 1, '2023-08-03 14:42:49', '2023-08-03 14:42:49', '', '1'")
        # add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_current_channel(DB_HOST, DB_NAME, channel_config, addr_config, channel_config_group, algo_config_data,
                            current_sql_config)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        create_collect_current(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, amp_section=(0.2, 1.1), time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET bb_fundamental_amplitude=1.2 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        print("第三步，生成并导入数据库数据完毕")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name)
        print("第五步，导出csv完毕")

        # 第六步，检查预期结果
        # 继保仪输出电流确保线路1 A相和线路2 A相的采集电流频率为48Hz，等待“电流频率异常”事件上报
        # 线路1和线路2正常上报“电流频率异常”事件
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据幅值异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 63) & (df_not_recovered["event_source"] == "电流线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)

        assert len(df_1) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET bb_fundamental_amplitude=1 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出电流确保线路1 B相采集电流幅值为50Hz，等待自动自诊断查看自诊断事件
        已恢复事件中显示“电流频率异常”事件，事件来源为电流线路：1_1，恢复时间为首次采集到电流频率为50Hz的时间点。
        """
        df_2 = df_recovered[
            (df_recovered["event_name"] == "电流数据幅值异常") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 63) & (df_recovered["event_source"] == "电流线路：1_1") &
            (df_recovered["recovery_time"] == assign_time_1)]
        print(df_2)
        # 无恢复时间
        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET cc_fundamental_amplitude=0.1 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出确保线路1 A相电流频率为48.9Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中上报“电流频率异常”事件，事件类型为'异常'，事件编码为'64'，事件来源为电流线路：1_1，事件开始时间为首次采集到电流频率为48.9Hz的时间点，无恢复时间
        """
        df_3 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据幅值异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 63) & (df_not_recovered["event_source"] == "电流线路：1_1") &
            (df_not_recovered["start_time"] == assign_time_1)]
        print(df_3)

        assert len(df_3) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET cc_fundamental_amplitude=1 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_4")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        删除电流线路1，查看自诊断事件
        已恢复事件中显示线路1_1的电流频率异常事件，恢复时间为删除线路时的时间，恢复原因标注为“该配置已被删除”，未恢复事件中继续显示线路100_100的电流频率异常事件
        """
        df_4 = df_recovered[
            (df_recovered["event_name"] == "电流数据幅值异常") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 63) & (df_recovered["event_source"] == "电流线路：1_1") &
            (df_recovered["recovery_time"] == assign_time_1)]
        print(df_4)
        # 无恢复时间
        assert len(df_4) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        set_sql_current_1A(ip, DB_NAME, min=0, max=1.25)
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1449(ip, DB_NAME, v_arg_list, scene_name, current_sql_config, channel_config, addr_config,
                       channel_config_group, algo_config_data, transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip
        # 重装站端环境
        initial_data(DB_HOST, port=10088, username="oetsky", password=os_password)

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        set_sql_current_5A(ip, DB_NAME, min=0.2, max=6)
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电流采集单元一', '02', '698', '192.168.10.100', '5000', 1, '2023-08-03 14:42:49', '2023-08-03 14:42:49', '', '1'")
        # add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_current_channel(DB_HOST, DB_NAME, channel_config, addr_config, channel_config_group, algo_config_data,
                            current_sql_config)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        create_collect_current(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, amp_section=(0.2, 1.1), time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET aa_fundamental_amplitude=0.2 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        print("第三步，生成并导入数据库数据完毕")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name)
        print("第五步，导出csv完毕")

        # 第六步，检查预期结果
        # 通过数据库工具连接X86数据库，打开da_voltage_data_temp电流数据采集表，将'collect_time'字段倒序，选中时间最近的一条线路通道为1的电流采集数据后幅值，然后添加一条数据并粘贴幅值的数据，修改ID号保持唯一，修改collet_time时间为原时间+1s，等待站端软件自动自诊断，查看自诊断事件列表
        # 未恢复事件中无“电流数据重复”事件，已恢复事件中上报“电流数据重复”事件，事件类型为'异常'，事件编码为'62'，事件来源为电流线路:1_1，事件开始时间为重复数据所在时间点，恢复时间与开始时间相同
        df_1 = df_not_recovered[(df_not_recovered["event_name"] == "电流数据幅值异常")]
        df_2 = df_recovered[(df_recovered["event_name"] == "电流数据幅值异常")]
        print(df_1)
        print(df_2)

        assert len(df_1) == 0
        assert len(df_2) == 0
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET aa_fundamental_amplitude=0.1 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出确保线路1 A相电流频率为48.9Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中上报“电流频率异常”事件，事件类型为'异常'，事件编码为'64'，事件来源为电流线路：1_1，事件开始时间为首次采集到电流频率为48.9Hz的时间点，无恢复时间
        """
        df_3 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据幅值异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 63) & (df_not_recovered["event_source"] == "电流线路：1_1") &
            (df_not_recovered["start_time"] == assign_time_1)]
        print(df_3)
        # 无恢复时间
        assert df_3.iloc[0]["recovery_time"] == None
        assert len(df_3) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET aa_fundamental_amplitude=6 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出确保线路1 A相电流频率为48.9Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中上报“电流频率异常”事件，事件类型为'异常'，事件编码为'64'，事件来源为电流线路：1_1，事件开始时间为首次采集到电流频率为48.9Hz的时间点，无恢复时间
        """
        df_4 = df_not_recovered[(df_not_recovered["event_name"] == "电流数据幅值异常")]
        df_5 = df_recovered[
            (df_recovered["event_name"] == "电流数据幅值异常") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 63) & (df_recovered["event_source"] == "电流线路：1_1") &
            (df_recovered["recovery_time"] == assign_time_1)]
        print(df_4)
        print(df_5)
        assert len(df_4) == 0
        assert len(df_5) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET aa_fundamental_amplitude=6.1 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_4")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出确保线路1 A相电流频率为48.9Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中上报“电流频率异常”事件，事件类型为'异常'，事件编码为'64'，事件来源为电流线路：1_1，事件开始时间为首次采集到电流频率为48.9Hz的时间点，无恢复时间
        """
        df_6 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据幅值异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 63) & (df_not_recovered["event_source"] == "电流线路：1_1") &
            (df_not_recovered["start_time"] == assign_time_1)]
        print(df_6)
        # 无恢复时间
        assert df_6.iloc[0]["recovery_time"] == None
        assert len(df_6) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET aa_fundamental_amplitude=6.1 WHERE channel_num=100 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_5")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        修改继保仪输出确保线路2 A相电流频率为51.1Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中新增上报“电流频率异常”事件，事件来源为电流线路：100_100，事件开始时间为首次采集到电流幅值为51.1Hz的时间点，无恢复时间
        """
        df_7 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据幅值异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 63) & (df_not_recovered["event_source"] == "电流线路：100_100") &
            (df_not_recovered["start_time"] == assign_time_1)]
        print(df_7)
        # 无恢复时间
        assert df_7.iloc[0]["recovery_time"] == None
        assert len(df_7) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET aa_fundamental_amplitude=5 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_6")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤5，修改继保仪输出确保线路1 A相电流频率为50Hz，线路2 A相电流频率持续保持为51.1Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中只有线路2的“电流频率异常”事件，线路1的“电流频率异常”事件已不在未恢复列表中，已恢复事件中包含线路1的“电流频率异常”事件，事件恢复时间为首次采集到电流频率为50Hz的时间点。
        """
        df_8 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据幅值异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 63) & (df_not_recovered["event_source"] == "电流线路：100_100")]
        df_9 = df_recovered[
            (df_recovered["event_name"] == "电流数据幅值异常") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 63) & (df_recovered["event_source"] == "电流线路：1_1") &
            (df_recovered["recovery_time"] == assign_time_1)]
        print(df_8)
        print(df_9)
        # 无恢复时间
        assert len(df_8) == 1
        assert len(df_9) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        set_sql_current_5A(ip, DB_NAME, min=0, max=6.25)
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1450(ip, DB_NAME, v_arg_list, scene_name, current_sql_config, channel_config, addr_config,
                       channel_config_group,
                       algo_config_data, transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip
        # 重装站端环境
        initial_data(DB_HOST, port=10088, username="oetsky", password=os_password)

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        set_sql_current_5A(ip, DB_NAME, min=0.2, max=6)
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电流采集单元一', '02', '698', '192.168.10.100', '5000', 1, '2023-08-03 14:42:49', '2023-08-03 14:42:49', '', '1'")
        # add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_current_channel(DB_HOST, DB_NAME, channel_config, addr_config, channel_config_group, algo_config_data,
                            current_sql_config)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        create_collect_current(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, amp_section=(0.2, 1.1), time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET aa_fundamental_amplitude=6.1 WHERE collect_time>='{}';".format(
                assign_time))
        print("第三步，生成并导入数据库数据完毕")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name)
        print("第五步，导出csv完毕")

        # 第六步，检查预期结果
        # 继保仪输出电流确保线路1 A相和线路2 A相的采集电流频率为48Hz，等待“电流频率异常”事件上报
        # 线路1和线路2正常上报“电流频率异常”事件
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据幅值异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 63) & (df_not_recovered["event_source"] == "电流线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        df_2 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据幅值异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 63) & (df_not_recovered["event_source"] == "电流线路：100_100") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)
        print(df_2)

        assert len(df_1) == 1
        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        # 删除线路1
        remove_channel(ip, 8082, username, 1)
        # execute_sql("DELETE FROM dv_current_channel WHERE channel_num=1;")
        # execute_sql("DELETE FROM addr_current_channel WHERE channel_num=1;")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        删除电流线路1，查看自诊断事件
        已恢复事件中显示线路1_1的电流频率异常事件，恢复时间为删除线路时的时间，恢复原因标注为“该配置已被删除”，未恢复事件中继续显示线路100_100的电流频率异常事件
        """
        df_3 = df_recovered[
            (df_recovered["event_name"] == "电流数据幅值异常") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 63) & (df_recovered["event_source"] == "电流线路：1_1") &
            (df_recovered["recovery_reason"] == "线路不存在，恢复异常事件")]
        df_4 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据幅值异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 63) & (df_not_recovered["event_source"] == "电流线路：100_100")]
        print(df_3)
        print(df_4)
        # 无恢复时间
        assert len(df_3) == 1
        assert len(df_4) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        # 重新添加线路1
        add_current_2_channel(DB_HOST, 8082, username)
        # only_add_current_channel(DB_HOST, DB_NAME, channel_config, addr_config, channel_config_group, algo_config_data)

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出确保线路1 A相电流频率为48.9Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中上报“电流频率异常”事件，事件类型为'异常'，事件编码为'64'，事件来源为电流线路：1_1，事件开始时间为首次采集到电流频率为48.9Hz的时间点，无恢复时间
        """
        df_5 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据幅值异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 63) & (df_not_recovered["event_source"] == "电流线路：1_1")]
        print(df_5)
        assert len(df_5) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        set_sql_current_5A(ip, DB_NAME, min=0, max=6.25)
        write_txt(scene_name + ":" + result + "\r")


def all_flow_ILAE_1451(ip, DB_NAME, v_arg_list, scene_name, current_sql_config, channel_config, addr_config,
                       channel_config_group,
                       algo_config_data, transformer_parm, time_data):
    """
    全流程测试
    :param ip:
    :param port:
    :param username:
    :param DB_NAME:
    :param v_arg_list:
    :param channel_config:
    :return:
    """
    result = "fail"
    try:
        print("{}：开始测试".format(scene_name))
        DB_HOST = ip
        # 重装站端环境
        initial_data(DB_HOST, port=10088, username="oetsky", password=os_password)

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        print("第一步，等待1、2、3或者6,7,8的时间开始测试完毕")

        # 第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置
        set_sql_current_5A(ip, DB_NAME, min=0.2, max=6)
        set_tcp_interface_status(DB_HOST, DB_NAME,
                                 "1, '电流采集单元一', '02', '698', '192.168.10.100', '5000', 1, '2023-08-03 14:42:49', '2023-08-03 14:42:49', '', '1'")
        # add_fs_voltage_transformer(DB_HOST, DB_NAME, transformer_parm)
        add_current_channel(DB_HOST, DB_NAME, channel_config, addr_config, channel_config_group, algo_config_data,
                            current_sql_config)
        print("第二步，设置采集单元状态为已经打开，添加线路数据，添加算法配置完毕")

        # 第三步，生成并导入数据库数据
        create_collect_current(
            p_datetime=(datetime.datetime.now().replace(second=0) + datetime.timedelta(minutes=time_data[0])).strftime(
                "%Y-%m-%d %H:%M:%S"), v_list=v_arg_list, amp_section=(0.2, 1.1), time=time_data[1])
        assign_time = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET bb_fundamental_amplitude=6.1 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time))
        print("第三步，生成并导入数据库数据完毕")

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name)
        print("第五步，导出csv完毕")

        # 第六步，检查预期结果
        # 继保仪输出电流确保线路1 A相和线路2 A相的采集电流频率为48Hz，等待“电流频率异常”事件上报
        # 线路1和线路2正常上报“电流频率异常”事件
        df_1 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据幅值异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 63) & (df_not_recovered["event_source"] == "电流线路：1_1") &
            (df_not_recovered["start_time"] == assign_time)]
        print(df_1)

        assert len(df_1) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET bb_fundamental_amplitude=5 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_2")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出电流确保线路1 B相采集电流幅值为50Hz，等待自动自诊断查看自诊断事件
        已恢复事件中显示“电流频率异常”事件，事件来源为电流线路：1_1，恢复时间为首次采集到电流频率为50Hz的时间点。
        """
        df_2 = df_recovered[
            (df_recovered["event_name"] == "电流数据幅值异常") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 63) & (df_recovered["event_source"] == "电流线路：1_1") &
            (df_recovered["recovery_time"] == assign_time_1)]
        print(df_2)
        # 无恢复时间
        assert len(df_2) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET cc_fundamental_amplitude=0.1 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_3")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        继续步骤1，修改继保仪输出确保线路1 A相电流频率为48.9Hz，等待自动自诊断后查看自诊断事件列表
        未恢复事件中上报“电流频率异常”事件，事件类型为'异常'，事件编码为'64'，事件来源为电流线路：1_1，事件开始时间为首次采集到电流频率为48.9Hz的时间点，无恢复时间
        """
        df_3 = df_not_recovered[
            (df_not_recovered["event_name"] == "电流数据幅值异常") & (df_not_recovered["event_type"] == 1) &
            (df_not_recovered["event_code"] == 63) & (df_not_recovered["event_source"] == "电流线路：1_1") &
            (df_not_recovered["start_time"] == assign_time_1)]
        print(df_3)

        assert len(df_3) == 1
        print("第六步，检查预期结果完毕")

        # 第一步，等待1、2、3或者6,7,8的时间开始测试
        wait_time()
        assign_time_1 = datetime.datetime.now().replace(second=0).strftime("%Y-%m-%d %H:%M:%S")
        execute_sql(
            "UPDATE da_current_data_temp SET cc_fundamental_amplitude=5 WHERE channel_num=1 and collect_time>='{}';".format(
                assign_time_1))

        # 第四步，等待自诊断事件完成
        wait_evevt_done()
        print("第四步，等待自诊断事件完成")

        # 第五步，导出csv
        df_recovered, df_not_recovered = export_csv(DB_HOST, DB_NAME, scene_name + "_4")
        print("第五步，导出csv完毕")
        print(df_recovered)
        print(df_not_recovered)

        # 第六步，检查预期结果
        """
        删除电流线路1，查看自诊断事件
        已恢复事件中显示线路1_1的电流频率异常事件，恢复时间为删除线路时的时间，恢复原因标注为“该配置已被删除”，未恢复事件中继续显示线路100_100的电流频率异常事件
        """
        df_4 = df_recovered[
            (df_recovered["event_name"] == "电流数据幅值异常") & (df_recovered["event_type"] == 1) &
            (df_recovered["event_code"] == 63) & (df_recovered["event_source"] == "电流线路：1_1") &
            (df_recovered["recovery_time"] == assign_time_1)]
        print(df_4)
        # 无恢复时间
        assert len(df_4) == 1
        print("第六步，检查预期结果完毕")

        result = "pass"
    except Exception as e:
        print(e)
        print("出现异常：{}".format(scene_name))
    finally:
        set_sql_current_5A(ip, DB_NAME, min=0, max=6.25)
        write_txt(scene_name + ":" + result + "\r")


def wait_time():
    """
    等待分钟为1,2,3或者6,7,8的时间点
    :return:
    """
    now_time = datetime.datetime.now()
    minute_time = datetime.datetime.now().minute
    print(now_time)
    print(minute_time)
    certain_minute = [i * 5 + 1 for i in range(12)] + [i * 5 + 2 for i in range(12)] + [i * 5 + 3 for i in range(12)]
    # 列表排序
    certain_minute.sort()
    print(certain_minute)
    for i in range(60 * 5):
        if minute_time in certain_minute:
            break
        else:
            time.sleep(1)
            minute_time = datetime.datetime.now().minute
            now_time = datetime.datetime.now()
            print("wait_time")
            print(minute_time)
            print(now_time)


def skip_4_9_minute():
    """
    遇到分钟为4或者9的时候，等待两分钟
    :return:
    """
    now_time = datetime.datetime.now()
    minute_time = datetime.datetime.now().minute
    print(now_time)
    print(minute_time)
    certain_minute = [i * 5 + 4 for i in range(12)] + [i * 5 + 9 for i in range(12)]
    # 列表排序
    certain_minute.sort()
    print(certain_minute)
    if minute_time in certain_minute:
        time.sleep(120)
        print("延时120秒跳过时间为4或者9的分钟点")


def set_sql_current_amp(DB_HOST, DB_NAME, min_frequency=49, max_frequency=51):
    """
    执行SQL，修改数据库电压幅值
    :param DB_HOST:
    :param DB_NAME:
    :param update_channel_num:
    :param pre_datetime:
    :return:
    """
    POOL = PooledDB(creator=pymysql, maxconnections=6, mincached=2, maxcached=5, maxshared=3, blocking=True,
                    maxusage=None, setsession=[], ping=0, host=DB_HOST, port=3306, user='oetsky', password='Oetsky@123',
                    database=DB_NAME, charset='utf8')
    conn = POOL.connection()
    cursor = conn.cursor()
    # 执行SQL，电流频率
    cursor.execute(
        "UPDATE sys_config set config_value={} WHERE config_key='current.frequency_max';".format(
            max_frequency))
    cursor.execute(
        "UPDATE sys_config set config_value={} WHERE config_key='current.frequency_min';".format(
            min_frequency))
    conn.commit()
    cursor.close()
    conn.close()


def set_sql_current_1A(DB_HOST, DB_NAME, min=0, max=1.25):
    """
    执行SQL，修改数据库电压幅值
    :param DB_HOST:
    :param DB_NAME:
    :param update_channel_num:
    :param pre_datetime:
    :return:
    """
    POOL = PooledDB(creator=pymysql, maxconnections=6, mincached=2, maxcached=5, maxshared=3, blocking=True,
                    maxusage=None, setsession=[], ping=0, host=DB_HOST, port=3306, user='oetsky', password='Oetsky@123',
                    database=DB_NAME, charset='utf8')
    conn = POOL.connection()
    cursor = conn.cursor()
    # 执行SQL，电流频率
    cursor.execute(
        "UPDATE sys_config set config_value={} WHERE config_key='current.JbfzMax1A';".format(max))
    cursor.execute(
        "UPDATE sys_config set config_value={} WHERE config_key='current.JbfzMin1A';".format(min))
    conn.commit()
    cursor.close()
    conn.close()


def set_sql_current_5A(DB_HOST, DB_NAME, min=0, max=6.25):
    """
    执行SQL，修改数据库电压幅值
    :param DB_HOST:
    :param DB_NAME:
    :param update_channel_num:
    :param pre_datetime:
    :return:
    """
    POOL = PooledDB(creator=pymysql, maxconnections=6, mincached=2, maxcached=5, maxshared=3, blocking=True,
                    maxusage=None, setsession=[], ping=0, host=DB_HOST, port=3306, user='oetsky', password='Oetsky@123',
                    database=DB_NAME, charset='utf8')
    conn = POOL.connection()
    cursor = conn.cursor()
    # 执行SQL，电流频率
    cursor.execute(
        "UPDATE sys_config set config_value={} WHERE config_key='current.JbfzMax5A';".format(max))
    cursor.execute(
        "UPDATE sys_config set config_value={} WHERE config_key='current.JbfzMin5A';".format(min))
    conn.commit()
    cursor.close()
    conn.close()


if __name__ == '__main__':
    # start_time = time.time()
    # wait_evevt_done()
    # print(time.time() - start_time)
    # set_tcp_interface_status(("192.168.1.70", 'cvt_client_prod',  "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00',  '2023-07-18 19:50:00', NULL, '2'")
    # set_tcp_interface_status(("192.168.1.70", 'cvt_client_prod',  "")
    # set_tcp_interface_status("192.168.1.70", 'cvt_client_prod',
    #                          "1, '电压采集单元一', '01', '698', '192.168.10.100', '5000', 1, '2023-07-18 19:50:00', '2023-07-18 19:50:00', NULL, '2'")
    # set_sql_current_1A(ip, DB_NAME, min=0.2, max=1.1)
    set_sql_current_5A(ip, DB_NAME, min=0.2, max=6)
    # remove_channel(ip, 8082, "admin", 2)
    # add_current_4_channel(ip, 8082, "admin")
    # add_current_2_channel(ip, 8082, username)
